├── fiduswriter └── gitrepo_export │ ├── __init__.py │ ├── helpers │ ├── __init__.py │ ├── github.py │ └── gitlab.py │ ├── migrations │ ├── __init__.py │ ├── 0002_bookrepository_export_docx_bookrepository_export_odt.py │ └── 0001_initial.py │ ├── static │ └── js │ │ ├── modules │ │ └── gitrepo_export │ │ │ ├── github │ │ │ ├── index.js │ │ │ ├── tools │ │ │ │ ├── index.js │ │ │ │ ├── promise_chain.js │ │ │ │ ├── commit_tree.js │ │ │ │ ├── commit_file.js │ │ │ │ └── commit_zip_contents.js │ │ │ ├── book_exporters.js │ │ │ └── book_processor.js │ │ │ ├── gitlab │ │ │ ├── index.js │ │ │ ├── tools │ │ │ │ ├── index.js │ │ │ │ ├── zip2blobs.js │ │ │ │ └── commit.js │ │ │ ├── book_exporters.js │ │ │ └── book_processor.js │ │ │ ├── index.js │ │ │ ├── tools.js │ │ │ ├── templates.js │ │ │ └── books_overview.js │ │ └── plugins │ │ └── books_overview │ │ └── gitrepo_export.js │ ├── locale │ ├── bg │ │ └── LC_MESSAGES │ │ │ ├── djangojs.mo │ │ │ └── djangojs.po │ ├── de │ │ └── LC_MESSAGES │ │ │ ├── djangojs.mo │ │ │ └── djangojs.po │ ├── es │ │ └── LC_MESSAGES │ │ │ ├── djangojs.mo │ │ │ └── djangojs.po │ ├── fr │ │ └── LC_MESSAGES │ │ │ ├── djangojs.mo │ │ │ └── djangojs.po │ ├── it │ │ └── LC_MESSAGES │ │ │ ├── djangojs.mo │ │ │ └── djangojs.po │ └── pt_BR │ │ └── LC_MESSAGES │ │ ├── djangojs.mo │ │ └── djangojs.po │ ├── apps.py │ ├── admin.py │ ├── urls.py │ ├── models.py │ └── views.py ├── dev-requirements.txt ├── ci ├── configuration.py └── .coveragerc ├── .editorconfig ├── MANIFEST.in ├── .gitignore ├── pyproject.toml ├── setup.py ├── .pre-commit-config.yaml ├── stylelint.config.js ├── README.md ├── .github └── workflows │ └── main.yml ├── lint └── django_import_resolver.js ├── biome.json └── LICENSE /fiduswriter/gitrepo_export/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/helpers/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /dev-requirements.txt: -------------------------------------------------------------------------------- 1 | pre-commit==4.0.1 2 | fiduswriter 3 | -------------------------------------------------------------------------------- /ci/configuration.py: -------------------------------------------------------------------------------- 1 | INSTALLED_APPS = ["book", "gitrepo_export"] 2 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 4 6 | 7 | [*.py] 8 | insert_final_newline = true -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/static/js/modules/gitrepo_export/github/index.js: -------------------------------------------------------------------------------- 1 | export {GithubBookProcessor} from "./book_processor" 2 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/static/js/modules/gitrepo_export/gitlab/index.js: -------------------------------------------------------------------------------- 1 | export {GitlabBookProcessor} from "./book_processor" 2 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/static/js/modules/gitrepo_export/index.js: -------------------------------------------------------------------------------- 1 | export {GitrepoExporterBooksOverview} from "./books_overview" 2 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/static/js/plugins/books_overview/gitrepo_export.js: -------------------------------------------------------------------------------- 1 | export {GitrepoExporterBooksOverview} from "../../modules/gitrepo_export" 2 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/static/js/modules/gitrepo_export/gitlab/tools/index.js: -------------------------------------------------------------------------------- 1 | export {commitFiles} from "./commit" 2 | export {zipToBlobs} from "./zip2blobs" 3 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/locale/bg/LC_MESSAGES/djangojs.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fiduswriter/fiduswriter-gitrepo-export/main/fiduswriter/gitrepo_export/locale/bg/LC_MESSAGES/djangojs.mo -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/locale/de/LC_MESSAGES/djangojs.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fiduswriter/fiduswriter-gitrepo-export/main/fiduswriter/gitrepo_export/locale/de/LC_MESSAGES/djangojs.mo -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/locale/es/LC_MESSAGES/djangojs.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fiduswriter/fiduswriter-gitrepo-export/main/fiduswriter/gitrepo_export/locale/es/LC_MESSAGES/djangojs.mo -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/locale/fr/LC_MESSAGES/djangojs.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fiduswriter/fiduswriter-gitrepo-export/main/fiduswriter/gitrepo_export/locale/fr/LC_MESSAGES/djangojs.mo -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/locale/it/LC_MESSAGES/djangojs.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fiduswriter/fiduswriter-gitrepo-export/main/fiduswriter/gitrepo_export/locale/it/LC_MESSAGES/djangojs.mo -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class Config(AppConfig): 5 | name = "gitrepo_export" 6 | default_auto_field = "django.db.models.AutoField" 7 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/locale/pt_BR/LC_MESSAGES/djangojs.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fiduswriter/fiduswriter-gitrepo-export/main/fiduswriter/gitrepo_export/locale/pt_BR/LC_MESSAGES/djangojs.mo -------------------------------------------------------------------------------- /ci/.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | parallel = True 3 | concurrency = thread,multiprocessing 4 | sigterm = True 5 | relative_files = True 6 | omit = 7 | *migrations* 8 | venv/* 9 | *virtualenv* 10 | configuration.py 11 | locale/* 12 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/static/js/modules/gitrepo_export/github/tools/index.js: -------------------------------------------------------------------------------- 1 | export {commitFile} from "./commit_file" 2 | export {commitZipContents} from "./commit_zip_contents" 3 | export {commitTree} from "./commit_tree" 4 | export {promiseChain} from "./promise_chain" 5 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from . import models 3 | 4 | 5 | class BookRepositoryAdmin(admin.ModelAdmin): 6 | pass 7 | 8 | 9 | admin.site.register(models.BookRepository, BookRepositoryAdmin) 10 | 11 | 12 | class RepoInfoAdmin(admin.ModelAdmin): 13 | pass 14 | 15 | 16 | admin.site.register(models.RepoInfo, RepoInfoAdmin) 17 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE 2 | include README.rst 3 | recursive-include fiduswriter/gitrepo_export/static * 4 | recursive-include fiduswriter/gitrepo_export/fixtures * 5 | recursive-include fiduswriter/gitrepo_export/templates * 6 | recursive-include fiduswriter/gitrepo_export/locale * 7 | prune travis 8 | prune fiduswriter/venv 9 | prune venv 10 | prune fiduswriter/configuration.py 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *~ 3 | dist/ 4 | build/ 5 | fiduswriter_gitrepo_export.egg-info/ 6 | fiduswriter_gitrepo_export.egg-info/ 7 | __pycache__/ 8 | venv/ 9 | fiduswriter/.transpile 10 | fiduswriter/media 11 | fiduswriter/static-libs 12 | fiduswriter/static-transpile 13 | fiduswriter/static-collected 14 | fiduswriter/.coveragerc 15 | fiduswriter/configuration.py 16 | fiduswriter/fiduswriter.sql 17 | *.direnv 18 | .envrc 19 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/static/js/modules/gitrepo_export/github/tools/promise_chain.js: -------------------------------------------------------------------------------- 1 | // See https://decembersoft.com/posts/promises-in-serial-with-array-reduce/ 2 | 3 | export function promiseChain(tasks) { 4 | return tasks.reduce((promiseChain, currentTask) => { 5 | return promiseChain.then(chainResults => 6 | currentTask().then(currentResult => [ 7 | ...chainResults, 8 | currentResult 9 | ]) 10 | ) 11 | }, Promise.resolve([])) 12 | } 13 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/migrations/0002_bookrepository_export_docx_bookrepository_export_odt.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.15 on 2024-09-20 11:13 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | dependencies = [ 8 | ("gitrepo_export", "0001_initial"), 9 | ] 10 | 11 | operations = [ 12 | migrations.AddField( 13 | model_name="bookrepository", 14 | name="export_docx", 15 | field=models.BooleanField(default=False), 16 | preserve_default=False, 17 | ), 18 | migrations.AddField( 19 | model_name="bookrepository", 20 | name="export_odt", 21 | field=models.BooleanField(default=False), 22 | preserve_default=False, 23 | ), 24 | ] 25 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import re_path 2 | 3 | from . import views 4 | 5 | urlpatterns = [ 6 | re_path("^get_book_repos/$", views.get_book_repos, name="get_book_repos"), 7 | re_path( 8 | "^update_book_repo/$", views.update_book_repo, name="update_book_repo" 9 | ), 10 | re_path( 11 | "^get_git_repos/reload/$", 12 | views.get_git_repos, 13 | {"reload": True}, 14 | name="get_git_repos_reload", 15 | ), 16 | re_path("^get_git_repos/$", views.get_git_repos, name="get_git_repos"), 17 | re_path( 18 | "^get_gitlab_repo/(?P.*)/$", 19 | views.get_gitlab_repo, 20 | name="get_gitlab_repo", 21 | ), 22 | re_path( 23 | "^proxy_github/(?P.*)$", views.proxy_github, name="proxy_github" 24 | ), 25 | re_path( 26 | "^proxy_gitlab/(?P.*)$", views.proxy_gitlab, name="proxy_gitlab" 27 | ), 28 | ] 29 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools>=65.6.3", "wheel"] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "fiduswriter-gitrepo-export" 7 | description = "A Fidus Writer plugin to allow publishing of books to a Gitlab/Github repository." 8 | version = "4.0.0" 9 | readme = "README.md" 10 | license = {text = "AGPL-3.0-or-later"} 11 | authors = [ 12 | {email = "johannes@fiduswriter.org", name = "Johannes Wilm"}, 13 | ] 14 | classifiers=[ 15 | "Environment :: Web Environment", 16 | "Framework :: Django", 17 | "Framework :: Django :: 4.2", 18 | "Intended Audience :: Developers", 19 | "License :: OSI Approved :: GNU Affero General Public License v3", 20 | "Operating System :: OS Independent", 21 | "Programming Language :: Python", 22 | "Programming Language :: Python :: 3", 23 | "Topic :: Internet :: WWW/HTTP", 24 | "Topic :: Internet :: WWW/HTTP :: Dynamic Content", 25 | ] 26 | 27 | [project.urls] 28 | repository = "https://www.github.com/fiduswriter/fiduswriter-gitrepo-export" 29 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import os 2 | from glob import glob 3 | from setuptools import find_namespace_packages, setup 4 | from setuptools.command.build_py import build_py as _build_py 5 | 6 | 7 | # From https://github.com/pypa/setuptools/pull/1574 8 | class build_py(_build_py): 9 | def find_package_modules(self, package, package_dir): 10 | modules = super().find_package_modules(package, package_dir) 11 | patterns = self._get_platform_patterns( 12 | self.exclude_package_data, 13 | package, 14 | package_dir, 15 | ) 16 | 17 | excluded_module_files = [] 18 | for pattern in patterns: 19 | excluded_module_files.extend(glob(pattern)) 20 | 21 | for f in excluded_module_files: 22 | for module in modules: 23 | if module[2] == f: 24 | modules.remove(module) 25 | return modules 26 | 27 | 28 | os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir))) 29 | 30 | setup( 31 | packages=find_namespace_packages(), 32 | exclude_package_data={ 33 | "": ["configuration.py", "django-admin.py", "build/*"] 34 | }, 35 | include_package_data=True, 36 | cmdclass={"build_py": build_py}, 37 | ) 38 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.conf import settings as django_settings 3 | from book.models import Book 4 | 5 | REPO_TYPES = ( 6 | ("github", "GitHub"), 7 | ("gitlab", "GitLab"), 8 | ) 9 | 10 | 11 | class BookRepository(models.Model): 12 | book = models.ForeignKey(Book, on_delete=models.deletion.CASCADE) 13 | repo_id = models.IntegerField() 14 | repo_name = models.CharField( 15 | max_length=256, 16 | ) 17 | repo_type = models.CharField( 18 | max_length=6, 19 | choices=REPO_TYPES, 20 | ) 21 | export_epub = models.BooleanField() 22 | export_unpacked_epub = models.BooleanField() 23 | export_html = models.BooleanField() 24 | export_unified_html = models.BooleanField() 25 | export_latex = models.BooleanField() 26 | export_odt = models.BooleanField() 27 | export_docx = models.BooleanField() 28 | 29 | class Meta(object): 30 | verbose_name_plural = "Book repositories" 31 | 32 | 33 | class RepoInfo(models.Model): 34 | user = models.OneToOneField( 35 | django_settings.AUTH_USER_MODEL, 36 | on_delete=models.deletion.CASCADE, 37 | ) 38 | content = models.JSONField(default=list, null=True, blank=True) 39 | 40 | def __str__(self): 41 | return self.user.readable_name 42 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/psf/black-pre-commit-mirror 3 | rev: 24.10.0 4 | hooks: 5 | - id: black 6 | args: [--line-length=79] 7 | language_version: python3.13 8 | - repo: https://github.com/pycqa/flake8 9 | rev: '7.1.1' 10 | hooks: 11 | - id: flake8 12 | entry: flake8 --extend-ignore E203,E501 13 | - repo: https://github.com/biomejs/pre-commit 14 | rev: "75149f4e3b63c4df805860d7b04186d56dcbc05c" 15 | hooks: 16 | - id: biome-check 17 | #entry: biome check --files-ignore-unknown=true --no-errors-on-unmatched --fix --unsafe 18 | additional_dependencies: ["@biomejs/biome@1.9.2"] 19 | - repo: https://github.com/awebdeveloper/pre-commit-stylelint 20 | rev: "4200758f4cb2f53dd06898dd8dca35e4b8cfb785" 21 | hooks: 22 | - id: stylelint 23 | additional_dependencies: 24 | [ 25 | "stylelint@15.11.0", 26 | "stylelint-config-standard@34.0.0", 27 | "stylelint-value-no-unknown-custom-properties@5.0.0", 28 | "postcss@8.4.32", 29 | ] 30 | - repo: local 31 | hooks: 32 | - id: django-import-resolver 33 | name: Django Import Resolver 34 | entry: node lint/django_import_resolver.js 35 | language: node 36 | files: \.js$ 37 | additional_dependencies: ["acorn@8.10.0"] 38 | -------------------------------------------------------------------------------- /stylelint.config.js: -------------------------------------------------------------------------------- 1 | const path = require("path") 2 | const {execSync} = require("child_process") 3 | 4 | function getFidusWriterPath() { 5 | try { 6 | const fwPath = execSync( 7 | "python -c \"import fiduswriter; print(next(filter(lambda path: '/site-packages/' in path, fiduswriter.__path__), ''))\"" 8 | ) 9 | .toString() 10 | .trim() 11 | if (fwPath) { 12 | return fwPath 13 | } 14 | throw new Error("Fidus Writer not found") 15 | } catch (error) { 16 | console.error( 17 | "Failed to find Fidus Writer installation:", 18 | error.message 19 | ) 20 | process.exit(1) 21 | } 22 | } 23 | 24 | const fidusWriterPath = getFidusWriterPath() 25 | 26 | module.exports = { 27 | extends: "stylelint-config-standard", 28 | plugins: ["stylelint-value-no-unknown-custom-properties"], 29 | rules: { 30 | "color-hex-length": "long", 31 | "max-nesting-depth": 2, 32 | "csstools/value-no-unknown-custom-properties": [ 33 | true, 34 | { 35 | importFrom: [ 36 | path.join(fidusWriterPath, "base/static/css/colors.css") 37 | ] 38 | } 39 | ], 40 | "selector-class-pattern": [ 41 | "^(([a-z][a-z0-9]*)(-[a-z0-9]+)*)|(ProseMirror(-[a-z0-9]+)*)$", 42 | { 43 | message: 44 | "Selector should use lowercase and separate words with hyphens (selector-class-pattern)" 45 | } 46 | ] 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/static/js/modules/gitrepo_export/tools.js: -------------------------------------------------------------------------------- 1 | // Source https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest 2 | 3 | export function gitHashObject(content, utf8 = true) { 4 | let contentArray 5 | if (utf8) { 6 | contentArray = new TextEncoder().encode(content) 7 | } else { 8 | contentArray = new Uint8Array(content.length) 9 | for (let i = 0; i < content.length; i++) { 10 | contentArray[i] = content.charCodeAt(i) 11 | } 12 | } 13 | const prefixArray = new TextEncoder().encode( 14 | "blob " + contentArray.byteLength + "\0" 15 | ) // encode as (utf-8) Uint8Array 16 | 17 | // Join arrays 18 | const unifiedArray = new Uint8Array( 19 | prefixArray.byteLength + contentArray.byteLength 20 | ) 21 | unifiedArray.set(new Uint8Array(prefixArray), 0) 22 | unifiedArray.set(new Uint8Array(contentArray), prefixArray.byteLength) 23 | 24 | return crypto.subtle.digest("SHA-1", unifiedArray).then(hashBuffer => { 25 | const hashArray = Array.from(new Uint8Array(hashBuffer)) // convert buffer to byte array 26 | const hashHex = hashArray 27 | .map(b => b.toString(16).padStart(2, "0")) 28 | .join("") // convert bytes to hex string 29 | return hashHex 30 | }) 31 | } 32 | 33 | export function readBlobPromise(blob) { 34 | return new Promise((resolve, reject) => { 35 | const reader = new FileReader() 36 | reader.onload = () => resolve(reader.result.split("base64,")[1]) 37 | reader.onerror = reject 38 | reader.readAsDataURL(blob) 39 | }) 40 | } 41 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/static/js/modules/gitrepo_export/gitlab/tools/zip2blobs.js: -------------------------------------------------------------------------------- 1 | import {get} from "../../../common" 2 | 3 | export function zipToBlobs( 4 | outputList, 5 | binaryFiles, 6 | includeZips, 7 | parentDir = "" 8 | ) { 9 | const outputFiles = {} 10 | outputList.forEach(file => { 11 | outputFiles[`${parentDir}${file.filename}`] = new Blob([file.contents]) 12 | }) 13 | const commitBinaries = binaryFiles.map(file => 14 | get(file.url) 15 | .then(response => response.blob()) 16 | .then(blob => { 17 | outputFiles[`${parentDir}${file.filename}`] = blob 18 | }) 19 | ) 20 | const commitZips = import("jszip").then(({default: JSZip}) => { 21 | return includeZips.map(zipFile => 22 | get(zipFile.url) 23 | .then(response => response.blob()) 24 | .then(blob => { 25 | const zipfs = new JSZip() 26 | return zipfs.loadAsync(blob).then(() => { 27 | const files = [] 28 | zipfs.forEach(file => files.push(file)) 29 | return Promise.all( 30 | files.map(filepath => 31 | zipfs.files[filepath].async("blob") 32 | ) 33 | ).then(blobs => 34 | blobs.map((blob, index) => { 35 | const filepath = files[index] 36 | outputFiles[`${parentDir}${filepath}`] = blob 37 | }) 38 | ) 39 | }) 40 | }) 41 | ) 42 | }) 43 | return Promise.all(commitBinaries.concat(commitZips)).then( 44 | () => outputFiles 45 | ) 46 | } 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | fiduswriter-gitrepo-export 2 | ========================== 3 | 4 | A plugin to export books to GitLab/GitHub. 5 | 6 | To install: 7 | ----------- 8 | 9 | 1. Make sure you have installed the `fiduswriter-books` plugin and you have updated both `fiduswriter` and `fiduswriter-books` to the latest patch release. 10 | 11 | 2. Install this plugin (for example by running ``pip install fiduswriter-gitrepo-export``). 12 | 13 | 3. Enter the configuration file in an editor. If you have installed the Snap, you do this by running ``sudo fiduswriter.configure``. Otherwise open the file `configuration.py` in a text editor. 14 | 15 | 4. The default maximum size of a book is 2.5 MB. If some of your files will be larger than that, adjust ``DATA_UPLOAD_MAX_MEMORY_SIZE`` to something higher, for example 10MiB:: 16 | 17 | ```python 18 | DATA_UPLOAD_MAX_MEMORY_SIZE = 10485760 19 | ``` 20 | 21 | 5. Add "gitrepo_export" to ``INSTALLED_APPS``. 22 | 23 | *For GitHub* 24 | 25 | 6a. Add "allauth.socialaccount.providers.github" to ``INSTALLED_APPS``. 26 | 27 | 7a. Add repo rights for the github connector like this:: 28 | 29 | ```python 30 | SOCIALACCOUNT_PROVIDERS = { 31 | 'github': { 32 | 'SCOPE': [ 33 | 'repo', 34 | 'user:email', 35 | ], 36 | } 37 | } 38 | ``` 39 | 40 | 8a. Exit the editor and save the configuration file. 41 | 42 | 9a. Set up GitHub as one of the connected login options. See instructions here: https://docs.allauth.org/en/latest/socialaccount/providers/github.html . The callback URL will be in the format https://DOMAIN.NAME/api/github/github/login/callback/ 43 | 44 | *For GitLab* 45 | 46 | 6b. Add "allauth.socialaccount.providers.gitlab" to ``INSTALLED_APPS``. 47 | 48 | 7b. Add repo rights for the gitlab connector like this:: 49 | 50 | ```python 51 | SOCIALACCOUNT_PROVIDERS = { 52 | 'gitlab': { 53 | 'SCOPE': [ 54 | 'api', 55 | ], 56 | } 57 | } 58 | ``` 59 | 60 | 8b. Exit the editor and save the configuration file. 61 | 62 | 9b. Set up GitLab as one of the connected login options. See instructions here: https://docs.allauth.org/en/latest/socialaccount/providers/gitlab.html . The callback URL will be in the format https://DOMAIN.NAME/api/gitlab/gitlab/login/callback/ 63 | 64 | 65 | 66 | To use: 67 | ------- 68 | 69 | 1. Login to your Fidus Writer instance using GitHub/GitLab, or login with a regular account and connect a Gitlab/Github account on the profile page (https://DOMAIN.NAME/user/profile/) 70 | 71 | 2. Go to the books overview page. 72 | 73 | 3. Enter a book to set the gitrepo settings for the book. 74 | 75 | 4. Select the book in the overview and export to gitrepo via the dropdown menu. 76 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.2.4 on 2021-11-26 07:01 2 | 3 | from django.conf import settings 4 | from django.db import migrations, models 5 | import django.db.models.deletion 6 | 7 | 8 | class Migration(migrations.Migration): 9 | initial = True 10 | 11 | dependencies = [ 12 | ("book", "0012_remove_user_accessrights"), 13 | migrations.swappable_dependency(settings.AUTH_USER_MODEL), 14 | ] 15 | 16 | operations = [ 17 | migrations.CreateModel( 18 | name="RepoInfo", 19 | fields=[ 20 | ( 21 | "id", 22 | models.AutoField( 23 | auto_created=True, 24 | primary_key=True, 25 | serialize=False, 26 | verbose_name="ID", 27 | ), 28 | ), 29 | ( 30 | "content", 31 | models.JSONField(blank=True, default=list, null=True), 32 | ), 33 | ( 34 | "user", 35 | models.OneToOneField( 36 | on_delete=django.db.models.deletion.CASCADE, 37 | to=settings.AUTH_USER_MODEL, 38 | ), 39 | ), 40 | ], 41 | ), 42 | migrations.CreateModel( 43 | name="BookRepository", 44 | fields=[ 45 | ( 46 | "id", 47 | models.AutoField( 48 | auto_created=True, 49 | primary_key=True, 50 | serialize=False, 51 | verbose_name="ID", 52 | ), 53 | ), 54 | ("repo_id", models.IntegerField()), 55 | ("repo_name", models.CharField(max_length=256)), 56 | ( 57 | "repo_type", 58 | models.CharField( 59 | choices=[("github", "GitHub"), ("gitlab", "GitLab")], 60 | max_length=6, 61 | ), 62 | ), 63 | ("export_epub", models.BooleanField()), 64 | ("export_unpacked_epub", models.BooleanField()), 65 | ("export_html", models.BooleanField()), 66 | ("export_unified_html", models.BooleanField()), 67 | ("export_latex", models.BooleanField()), 68 | ( 69 | "book", 70 | models.ForeignKey( 71 | on_delete=django.db.models.deletion.CASCADE, 72 | to="book.book", 73 | ), 74 | ), 75 | ], 76 | options={ 77 | "verbose_name_plural": "Book repositories", 78 | }, 79 | ), 80 | ] 81 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/helpers/github.py: -------------------------------------------------------------------------------- 1 | import re 2 | import json 3 | 4 | from httpx import AsyncClient, Request 5 | from allauth.socialaccount.models import SocialToken 6 | 7 | ALLOWED_PATHS = [ 8 | re.compile(r"^repos/([\w\.\-@_]+)/([\w\.\-@_]+)/contents/"), 9 | re.compile(r"^user/repos$"), 10 | re.compile(r"^user/repos/reload$"), 11 | re.compile(r"^repos/([\w\.\-@_]+)/([\w\.\-@_]+)/git/blobs/([\w\d]+)$"), 12 | re.compile( 13 | r"^repos/([\w\.\-@_]+)/([\w\.\-@_]+)/git/refs/heads/([\w\d]+)$" 14 | ), 15 | re.compile(r"^repos/([\w\.\-@_]+)/([\w\.\-@_]+)/git/blobs$"), 16 | re.compile(r"^repos/([\w\.\-@_]+)/([\w\.\-@_]+)$"), 17 | re.compile(r"^repos/([\w\.\-@_]+)/([\w\.\-@_]+)/git/commits$"), 18 | re.compile(r"^repos/([\w\.\-@_]+)/([\w\.\-@_]+)/git/trees$"), 19 | ] 20 | 21 | 22 | async def proxy(path, user, query_string, body, method): 23 | if not any(regex.match(path) for regex in ALLOWED_PATHS): 24 | raise Exception("Path not permitted.") 25 | social_token = await SocialToken.objects.aget( 26 | account__user=user, account__provider="github" 27 | ) 28 | headers = get_headers(social_token.token) 29 | url = f"https://api.github.com/{path}" 30 | if query_string: 31 | url += "?" + query_string 32 | if method == "GET": 33 | body = None 34 | request = Request(method, url, headers=headers, content=body) 35 | async with AsyncClient( 36 | timeout=88 # Firefox times out after 90 seconds, so we need to return before that. 37 | ) as client: 38 | response = await client.send(request) 39 | return response 40 | 41 | 42 | def get_headers(token): 43 | return { 44 | "Authorization": f"token {token}", 45 | "User-Agent": "Fidus Writer", 46 | "Accept": "application/vnd.github.v3+json", 47 | } 48 | 49 | 50 | def githubrepo2repodata(github_repo): 51 | return { 52 | "type": "github", 53 | "name": github_repo["full_name"], 54 | "id": github_repo["id"], 55 | "branch": github_repo["default_branch"], 56 | } 57 | 58 | 59 | async def get_repos(github_token): 60 | headers = get_headers(github_token) 61 | repos = [] 62 | page = 1 63 | last_page = False 64 | while not last_page: 65 | url = f"https://api.github.com/user/repos?page={page}&per_page=100" 66 | request = Request("GET", url, headers=headers) 67 | async with AsyncClient( 68 | timeout=88 # Firefox times out after 90 seconds, so we need to return before that. 69 | ) as client: 70 | response = await client.send(request) 71 | content = json.loads(response.text) 72 | if isinstance(content, list): 73 | repos += map(githubrepo2repodata, content) 74 | if len(content) == 100: 75 | page += 1 76 | else: 77 | last_page = True 78 | else: 79 | last_page = True 80 | return repos 81 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/static/js/modules/gitrepo_export/github/tools/commit_tree.js: -------------------------------------------------------------------------------- 1 | import {getCookie, getJson} from "../../../common" 2 | 3 | export function commitTree(tree, commitMessage, repo) { 4 | let branch, parentSha 5 | const csrfToken = getCookie("csrftoken") 6 | return getJson( 7 | `/api/gitrepo_export/proxy_github/repos/${repo.name}`.replace( 8 | /\/\//, 9 | "/" 10 | ) 11 | ) 12 | .then(repoJson => { 13 | branch = repoJson.default_branch 14 | return getJson( 15 | `/api/gitrepo_export/proxy_github/repos/${repo.name}/git/refs/heads/${branch}`.replace( 16 | /\/\//, 17 | "/" 18 | ) 19 | ) 20 | }) 21 | .then(refsJson => { 22 | parentSha = refsJson.object.sha 23 | return fetch( 24 | `/api/gitrepo_export/proxy_github/repos/${repo.name}/git/trees`.replace( 25 | /\/\//, 26 | "/" 27 | ), 28 | { 29 | method: "POST", 30 | headers: { 31 | "X-CSRFToken": csrfToken 32 | }, 33 | credentials: "include", 34 | body: JSON.stringify({ 35 | tree, 36 | base_tree: parentSha 37 | }) 38 | } 39 | ) 40 | }) 41 | .then(response => response.json()) 42 | .then(treeJson => 43 | fetch( 44 | `/api/gitrepo_export/proxy_github/repos/${repo.name}/git/commits`.replace( 45 | /\/\//, 46 | "/" 47 | ), 48 | { 49 | method: "POST", 50 | headers: { 51 | "X-CSRFToken": csrfToken 52 | }, 53 | credentials: "include", 54 | body: JSON.stringify({ 55 | tree: treeJson.sha, 56 | parents: [parentSha], 57 | message: commitMessage 58 | }) 59 | } 60 | ) 61 | ) 62 | .then(response => response.json()) 63 | .then(commitJson => 64 | fetch( 65 | `/api/gitrepo_export/proxy_github/repos/${repo.name}/git/refs/heads/${branch}`.replace( 66 | /\/\//, 67 | "/" 68 | ), 69 | { 70 | method: "PATCH", 71 | headers: { 72 | "X-CSRFToken": csrfToken 73 | }, 74 | credentials: "include", 75 | body: JSON.stringify({ 76 | sha: commitJson.sha 77 | }) 78 | } 79 | ) 80 | ) 81 | } 82 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | - develop 8 | pull_request: 9 | branches: 10 | - main 11 | - develop 12 | 13 | # Allows you to run this workflow manually from the Actions tab 14 | workflow_dispatch: 15 | 16 | jobs: 17 | pre-commit: 18 | runs-on: ubuntu-latest 19 | steps: 20 | - uses: actions/checkout@v4 21 | - uses: actions/setup-python@v5 22 | with: 23 | python-version: "3.13" 24 | - name: Install dependencies 25 | run: | 26 | pip install pip --upgrade 27 | if grep version pyproject.toml | grep -q "dev"; 28 | then pip install https://github.com/fiduswriter/fiduswriter/archive/develop.zip; 29 | else pip install https://github.com/fiduswriter/fiduswriter/archive/main.zip; 30 | fi 31 | if grep version pyproject.toml | grep -q "dev"; 32 | then pip install https://github.com/fiduswriter/fiduswriter-books/archive/develop.zip; 33 | else pip install https://github.com/fiduswriter/fiduswriter-books/archive/main.zip; 34 | fi 35 | - uses: pre-commit/action@v3.0.1 36 | test: 37 | name: Run tests 38 | runs-on: ubuntu-latest 39 | steps: 40 | - name: Check out Git repository 41 | uses: actions/checkout@v3 42 | - name: Set up Python 43 | uses: actions/setup-python@v4 44 | with: 45 | python-version: "3.13" 46 | - name: Set up Node 47 | uses: actions/setup-node@v3 48 | with: 49 | node-version: 22 50 | - name: Install Python dependencies 51 | run: | 52 | pip install wheel 53 | pip install pip --upgrade 54 | if grep version pyproject.toml | grep -q "dev"; 55 | then pip install https://github.com/fiduswriter/fiduswriter/archive/develop.zip; 56 | else pip install https://github.com/fiduswriter/fiduswriter/archive/main.zip; 57 | fi 58 | if grep version pyproject.toml | grep -q "dev"; 59 | then pip install https://github.com/fiduswriter/fiduswriter-books/archive/develop.zip; 60 | else pip install https://github.com/fiduswriter/fiduswriter-books/archive/main.zip; 61 | fi 62 | cd fiduswriter 63 | mv ../ci/configuration.py ./ 64 | mv ../ci/.coveragerc ./ 65 | pip install requests[security] 66 | pip install coverage 67 | pip install coveralls 68 | pip install packaging 69 | pip install webdriver-manager 70 | pip install selenium 71 | coverage run $(which fiduswriter) setup --no-static 72 | - name: Run tests 73 | uses: nick-invision/retry@v2 74 | with: 75 | timeout_minutes: 8 76 | max_attempts: 3 77 | retry_on: error 78 | command: | 79 | cd fiduswriter 80 | coverage run $(which fiduswriter) test gitrepo_export 81 | - name: Coveralls 82 | run: | 83 | cd fiduswriter 84 | coverage combine 85 | coveralls --service=github 86 | env: 87 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 88 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/helpers/gitlab.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | from httpx import AsyncClient, Request 4 | from allauth.socialaccount.models import SocialToken 5 | from allauth.socialaccount.providers.gitlab.views import GitLabOAuth2Adapter 6 | 7 | 8 | class URLTranslator(GitLabOAuth2Adapter): 9 | def get_url(self, path): 10 | return self._build_url("/api/v4/" + path) 11 | 12 | 13 | async def proxy(request, path, user, query_string, body, method): 14 | social_token = await SocialToken.objects.aget( 15 | account__user=user, account__provider="gitlab" 16 | ) 17 | headers = get_headers(social_token.token) 18 | url_translator = URLTranslator(request) 19 | url = url_translator.get_url(path) 20 | if query_string: 21 | url += "?" + query_string 22 | if method == "GET": 23 | body = None 24 | request = Request(method, url, headers=headers, content=body) 25 | async with AsyncClient( 26 | timeout=88 # Firefox times out after 90 seconds, so we need to return before that. 27 | ) as client: 28 | response = await client.send(request) 29 | return response 30 | 31 | 32 | def get_headers(token): 33 | return { 34 | "Authorization": f"Bearer {token}", 35 | "User-Agent": "Fidus Writer", 36 | "Content-Type": "application/json", 37 | } 38 | 39 | 40 | async def get_repo(request, id, user): 41 | social_token = SocialToken.objects.get( 42 | account__user=user, account__provider="gitlab" 43 | ) 44 | headers = get_headers(social_token.token) 45 | files = [] 46 | url_translator = URLTranslator(request) 47 | next_url = url_translator.get_url( 48 | f"projects/{id}/repository/tree" 49 | "?recursive=true&per_page=4&pagination=keyset" 50 | ) 51 | while next_url: 52 | request = Request("GET", next_url, headers=headers) 53 | async with AsyncClient( 54 | timeout=88 # Firefox times out after 90 seconds, so we need to return before that. 55 | ) as client: 56 | response = await client.send(request) 57 | files += json.loads(response.text) 58 | next_url = False 59 | for link_info in response.headers["Link"].split(", "): 60 | link, rel = link_info.split("; ") 61 | if rel == 'rel="next"': 62 | next_url = link[1:-1] 63 | return files 64 | 65 | 66 | def gitlabrepo2repodata(gitlab_repo): 67 | return { 68 | "type": "gitlab", 69 | "name": gitlab_repo["path_with_namespace"], 70 | "id": gitlab_repo["id"], 71 | "branch": gitlab_repo["default_branch"], 72 | } 73 | 74 | 75 | async def get_repos(request, gitlab_token): 76 | # TODO: API documentation unclear on whether pagination is required. 77 | headers = get_headers(gitlab_token) 78 | repos = [] 79 | url_translator = URLTranslator(request) 80 | url = url_translator.get_url("projects?min_access_level=30&simple=true") 81 | request = Request("GET", url, headers=headers) 82 | async with AsyncClient( 83 | timeout=88 # Firefox times out after 90 seconds, so we need to return before that. 84 | ) as client: 85 | response = await client.send(request) 86 | content = json.loads(response.text) 87 | if isinstance(content, list): 88 | repos += map(gitlabrepo2repodata, content) 89 | return repos 90 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/static/js/modules/gitrepo_export/gitlab/tools/commit.js: -------------------------------------------------------------------------------- 1 | import {getCookie, getJson} from "../../../common" 2 | import {gitHashObject, readBlobPromise} from "../../tools" 3 | 4 | export function commitFiles(repo, commitMessage, fileBlobs) { 5 | return getJson(`/api/gitrepo_export/get_gitlab_repo/${repo.id}/`).then( 6 | ({files}) => { 7 | const commitUrl = `/api/gitrepo_export/proxy_gitlab/projects/${repo.id}/repository/commits` 8 | const getActions = Object.entries(fileBlobs).map( 9 | ([file_path, blob]) => 10 | readBlobPromise(blob).then(content => { 11 | const fileEntry = Array.isArray(files) 12 | ? files.find( 13 | entry => 14 | entry.type === "blob" && 15 | entry.path === file_path 16 | ) 17 | : false 18 | if (!fileEntry) { 19 | return { 20 | action: "create", 21 | encoding: "base64", 22 | file_path, 23 | content 24 | } 25 | } 26 | return gitHashObject( 27 | // Gitlab converts all line endings of text files to unix file line endings. 28 | blob.type.length 29 | ? atob(content) 30 | : atob(content).replace(/\r\n/g, "\n"), 31 | // UTF-8 files seem to have no type set. 32 | // Not sure if this is actually a viable way to distinguish between utf-8 and binary files. 33 | !blob.type.length 34 | ).then(sha => { 35 | if (sha === fileEntry.id) { 36 | return false 37 | } else { 38 | return { 39 | action: "update", 40 | encoding: "base64", 41 | file_path, 42 | content 43 | } 44 | } 45 | }) 46 | }) 47 | ) 48 | return Promise.all(getActions).then(actions => { 49 | actions = actions.filter(action => action) // Remove files that are not to be updated/added. 50 | if (!actions.length) { 51 | return 304 52 | } 53 | const commitData = { 54 | branch: "main", 55 | commit_message: commitMessage, 56 | actions 57 | } 58 | return fetch(commitUrl, { 59 | method: "POST", 60 | credentials: "include", 61 | headers: { 62 | "X-CSRFToken": getCookie("csrftoken") 63 | }, 64 | body: JSON.stringify(commitData) 65 | }).then(() => 201) 66 | }) 67 | } 68 | ) 69 | } 70 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/locale/it/LC_MESSAGES/djangojs.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "MIME-Version: 1.0\n" 4 | "Content-Type: text/plain; charset=UTF-8\n" 5 | "Content-Transfer-Encoding: 8bit\n" 6 | "X-Generator: POEditor.com\n" 7 | "Project-Id-Version: Fidus Writer Github Export\n" 8 | "Language: it\n" 9 | 10 | #: github_export/static/js/modules/github_export/book_processor.js:20 11 | msgid "There is no github repository registered for the book:" 12 | msgstr "Non esiste un repository github registrato per il libro:" 13 | 14 | #: github_export/static/js/modules/github_export/book_processor.js:27 15 | msgid "You do not have access to the repository:" 16 | msgstr "Non hai accesso al repository:" 17 | 18 | #: github_export/static/js/modules/github_export/book_processor.js:31 19 | msgid "Book publishing to Github initiated." 20 | msgstr "Iniziata la pubblicazione di libri su Github." 21 | 22 | #: github_export/static/js/modules/github_export/book_processor.js:58 23 | msgid "Book already up to date in repository." 24 | msgstr "Prenota già aggiornato nel repository." 25 | 26 | #: github_export/static/js/modules/github_export/book_processor.js:60 27 | msgid "Could not publish book to repository." 28 | msgstr "Impossibile pubblicare il libro nel repository." 29 | 30 | #: github_export/static/js/modules/github_export/book_processor.js:62 31 | msgid "Could not publish some parts of book to repository." 32 | msgstr "Impossibile pubblicare alcune parti del libro nel repository." 33 | 34 | #: github_export/static/js/modules/github_export/book_processor.js:64 35 | msgid "Book published to repository successfully!" 36 | msgstr "Libro pubblicato nel repository con successo!" 37 | 38 | #: github_export/static/js/modules/github_export/book_processor.js:66 39 | msgid "Book updated in repository successfully!" 40 | msgstr "Libro aggiornato nel repository con successo!" 41 | 42 | #: github_export/static/js/modules/github_export/books_overview.js:57 43 | msgid "Export to Github" 44 | msgstr "Esporta in Github" 45 | 46 | #: github_export/static/js/modules/github_export/books_overview.js:58 47 | msgid "Export selected to Github." 48 | msgstr "Esporta selezionato in Github." 49 | 50 | #: github_export/static/js/modules/github_export/books_overview.js:73 51 | msgid "Github" 52 | msgstr "Github" 53 | 54 | #: github_export/static/js/modules/github_export/books_overview.js:74 55 | msgid "Github related settings" 56 | msgstr "Impostazioni relative a Github" 57 | 58 | #: github_export/static/js/modules/github_export/templates.js:8 59 | msgid "Github repository" 60 | msgstr "Repository Github" 61 | 62 | #: github_export/static/js/modules/github_export/templates.js:8 63 | msgid "Select github repository to export to" 64 | msgstr "Seleziona il repository github in cui esportare" 65 | 66 | #: github_export/static/js/modules/github_export/templates.js:8 67 | msgid "Export EPUB" 68 | msgstr "Esporta EPUB" 69 | 70 | #: github_export/static/js/modules/github_export/templates.js:8 71 | msgid "Export unpacked EPUB" 72 | msgstr "Esporta EPUB decompresso" 73 | 74 | #: github_export/static/js/modules/github_export/templates.js:8 75 | msgid "Export HTML" 76 | msgstr "Esporta HTML" 77 | 78 | #: github_export/static/js/modules/github_export/templates.js:8 79 | msgid "Export LaTeX" 80 | msgstr "Esporta LaTeX" 81 | 82 | #: github_export/static/js/modules/github_export/tools/commit_file.js:17 83 | msgid "Update from Fidus Writer" 84 | msgstr "Aggiornamento da Fidus Writer" 85 | 86 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/locale/pt_BR/LC_MESSAGES/djangojs.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "MIME-Version: 1.0\n" 4 | "Content-Type: text/plain; charset=UTF-8\n" 5 | "Content-Transfer-Encoding: 8bit\n" 6 | "X-Generator: POEditor.com\n" 7 | "Project-Id-Version: Fidus Writer Github Export\n" 8 | "Language: pt-br\n" 9 | 10 | #: github_export/static/js/modules/github_export/book_processor.js:20 11 | msgid "There is no github repository registered for the book:" 12 | msgstr "Não há repositório github registrado para o livro:" 13 | 14 | #: github_export/static/js/modules/github_export/book_processor.js:27 15 | msgid "You do not have access to the repository:" 16 | msgstr "Você não tem acesso ao repositório:" 17 | 18 | #: github_export/static/js/modules/github_export/book_processor.js:31 19 | msgid "Book publishing to Github initiated." 20 | msgstr "A publicação do livro no Github foi iniciada." 21 | 22 | #: github_export/static/js/modules/github_export/book_processor.js:58 23 | msgid "Book already up to date in repository." 24 | msgstr "Livro já atualizado no repositório." 25 | 26 | #: github_export/static/js/modules/github_export/book_processor.js:60 27 | msgid "Could not publish book to repository." 28 | msgstr "Não foi possível publicar o livro no repositório." 29 | 30 | #: github_export/static/js/modules/github_export/book_processor.js:62 31 | msgid "Could not publish some parts of book to repository." 32 | msgstr "Não foi possível publicar algumas partes do livro no repositório." 33 | 34 | #: github_export/static/js/modules/github_export/book_processor.js:64 35 | msgid "Book published to repository successfully!" 36 | msgstr "Livro publicado no repositório com sucesso!" 37 | 38 | #: github_export/static/js/modules/github_export/book_processor.js:66 39 | msgid "Book updated in repository successfully!" 40 | msgstr "Livro atualizado no repositório com sucesso!" 41 | 42 | #: github_export/static/js/modules/github_export/books_overview.js:57 43 | msgid "Export to Github" 44 | msgstr "Exportar para Github" 45 | 46 | #: github_export/static/js/modules/github_export/books_overview.js:58 47 | msgid "Export selected to Github." 48 | msgstr "Exportar selecionados para o Github." 49 | 50 | #: github_export/static/js/modules/github_export/books_overview.js:73 51 | msgid "Github" 52 | msgstr "Github" 53 | 54 | #: github_export/static/js/modules/github_export/books_overview.js:74 55 | msgid "Github related settings" 56 | msgstr "Configurações relacionadas ao Github" 57 | 58 | #: github_export/static/js/modules/github_export/templates.js:8 59 | msgid "Github repository" 60 | msgstr "Repositório Github" 61 | 62 | #: github_export/static/js/modules/github_export/templates.js:8 63 | msgid "Select github repository to export to" 64 | msgstr "Selecione o repositório github para exportar" 65 | 66 | #: github_export/static/js/modules/github_export/templates.js:8 67 | msgid "Export EPUB" 68 | msgstr "Exportar EPUB" 69 | 70 | #: github_export/static/js/modules/github_export/templates.js:8 71 | msgid "Export unpacked EPUB" 72 | msgstr "Exportar EPUB descompactado" 73 | 74 | #: github_export/static/js/modules/github_export/templates.js:8 75 | msgid "Export HTML" 76 | msgstr "Exportar HTML" 77 | 78 | #: github_export/static/js/modules/github_export/templates.js:8 79 | msgid "Export LaTeX" 80 | msgstr "Exportar LaTeX" 81 | 82 | #: github_export/static/js/modules/github_export/tools/commit_file.js:17 83 | msgid "Update from Fidus Writer" 84 | msgstr "Atualização do escritor Fidus" 85 | 86 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/locale/bg/LC_MESSAGES/djangojs.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "MIME-Version: 1.0\n" 4 | "Content-Type: text/plain; charset=UTF-8\n" 5 | "Content-Transfer-Encoding: 8bit\n" 6 | "X-Generator: POEditor.com\n" 7 | "Project-Id-Version: Fidus Writer Github Export\n" 8 | "Language: bg\n" 9 | 10 | #: github_export/static/js/modules/github_export/book_processor.js:20 11 | msgid "There is no github repository registered for the book:" 12 | msgstr "Няма регистрирано хранилище на github за книгата:" 13 | 14 | #: github_export/static/js/modules/github_export/book_processor.js:27 15 | msgid "You do not have access to the repository:" 16 | msgstr "Нямате достъп до хранилището:" 17 | 18 | #: github_export/static/js/modules/github_export/book_processor.js:31 19 | msgid "Book publishing to Github initiated." 20 | msgstr "Инициирано издаване на книги в Github." 21 | 22 | #: github_export/static/js/modules/github_export/book_processor.js:58 23 | msgid "Book already up to date in repository." 24 | msgstr "Резервирайте вече актуално в хранилището." 25 | 26 | #: github_export/static/js/modules/github_export/book_processor.js:60 27 | msgid "Could not publish book to repository." 28 | msgstr "Не можа да публикува книга в хранилището." 29 | 30 | #: github_export/static/js/modules/github_export/book_processor.js:62 31 | msgid "Could not publish some parts of book to repository." 32 | msgstr "Не можах да публикувам някои части от книгата в хранилището." 33 | 34 | #: github_export/static/js/modules/github_export/book_processor.js:64 35 | msgid "Book published to repository successfully!" 36 | msgstr "Книгата е публикувана успешно в хранилището!" 37 | 38 | #: github_export/static/js/modules/github_export/book_processor.js:66 39 | msgid "Book updated in repository successfully!" 40 | msgstr "Книгата е актуализирана в хранилището успешно!" 41 | 42 | #: github_export/static/js/modules/github_export/books_overview.js:57 43 | msgid "Export to Github" 44 | msgstr "Експортирайте в Github" 45 | 46 | #: github_export/static/js/modules/github_export/books_overview.js:58 47 | msgid "Export selected to Github." 48 | msgstr "Експортирането е избрано в Github." 49 | 50 | #: github_export/static/js/modules/github_export/books_overview.js:73 51 | msgid "Github" 52 | msgstr "Github" 53 | 54 | #: github_export/static/js/modules/github_export/books_overview.js:74 55 | msgid "Github related settings" 56 | msgstr "Настройки, свързани с Github" 57 | 58 | #: github_export/static/js/modules/github_export/templates.js:8 59 | msgid "Github repository" 60 | msgstr "Хранилище на Github" 61 | 62 | #: github_export/static/js/modules/github_export/templates.js:8 63 | msgid "Select github repository to export to" 64 | msgstr "Изберете хранилището на github, в което да експортирате" 65 | 66 | #: github_export/static/js/modules/github_export/templates.js:8 67 | msgid "Export EPUB" 68 | msgstr "Експортиране на EPUB" 69 | 70 | #: github_export/static/js/modules/github_export/templates.js:8 71 | msgid "Export unpacked EPUB" 72 | msgstr "Експортирайте разопакован EPUB" 73 | 74 | #: github_export/static/js/modules/github_export/templates.js:8 75 | msgid "Export HTML" 76 | msgstr "Експортиране на HTML" 77 | 78 | #: github_export/static/js/modules/github_export/templates.js:8 79 | msgid "Export LaTeX" 80 | msgstr "Експортирайте LaTeX" 81 | 82 | #: github_export/static/js/modules/github_export/tools/commit_file.js:17 83 | msgid "Update from Fidus Writer" 84 | msgstr "Актуализация от Fidus Writer" 85 | 86 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/locale/fr/LC_MESSAGES/djangojs.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "MIME-Version: 1.0\n" 4 | "Content-Type: text/plain; charset=UTF-8\n" 5 | "Content-Transfer-Encoding: 8bit\n" 6 | "X-Generator: POEditor.com\n" 7 | "Project-Id-Version: Fidus Writer Github Export\n" 8 | "Language: fr\n" 9 | 10 | #: github_export/static/js/modules/github_export/book_processor.js:20 11 | msgid "There is no github repository registered for the book:" 12 | msgstr "Il n'y a pas de dépôt github enregistré pour le livre :" 13 | 14 | #: github_export/static/js/modules/github_export/book_processor.js:27 15 | msgid "You do not have access to the repository:" 16 | msgstr "Vous n'avez pas accès au référentiel :" 17 | 18 | #: github_export/static/js/modules/github_export/book_processor.js:31 19 | msgid "Book publishing to Github initiated." 20 | msgstr "Publication de livres sur Github initiée." 21 | 22 | #: github_export/static/js/modules/github_export/book_processor.js:58 23 | msgid "Book already up to date in repository." 24 | msgstr "Livre déjà à jour dans le référentiel." 25 | 26 | #: github_export/static/js/modules/github_export/book_processor.js:60 27 | msgid "Could not publish book to repository." 28 | msgstr "Impossible de publier le livre dans le référentiel." 29 | 30 | #: github_export/static/js/modules/github_export/book_processor.js:62 31 | msgid "Could not publish some parts of book to repository." 32 | msgstr "Impossible de publier certaines parties du livre dans le référentiel." 33 | 34 | #: github_export/static/js/modules/github_export/book_processor.js:64 35 | msgid "Book published to repository successfully!" 36 | msgstr "Livre publié dans le référentiel avec succès !" 37 | 38 | #: github_export/static/js/modules/github_export/book_processor.js:66 39 | msgid "Book updated in repository successfully!" 40 | msgstr "Livre mis à jour dans le référentiel avec succès !" 41 | 42 | #: github_export/static/js/modules/github_export/books_overview.js:57 43 | msgid "Export to Github" 44 | msgstr "Exporter vers Github" 45 | 46 | #: github_export/static/js/modules/github_export/books_overview.js:58 47 | msgid "Export selected to Github." 48 | msgstr "Exporter la sélection vers Github." 49 | 50 | #: github_export/static/js/modules/github_export/books_overview.js:73 51 | msgid "Github" 52 | msgstr "Github" 53 | 54 | #: github_export/static/js/modules/github_export/books_overview.js:74 55 | msgid "Github related settings" 56 | msgstr "Paramètres liés à Github" 57 | 58 | #: github_export/static/js/modules/github_export/templates.js:8 59 | msgid "Github repository" 60 | msgstr "Dépôt Github" 61 | 62 | #: github_export/static/js/modules/github_export/templates.js:8 63 | msgid "Select github repository to export to" 64 | msgstr "Sélectionnez le référentiel github vers lequel exporter" 65 | 66 | #: github_export/static/js/modules/github_export/templates.js:8 67 | msgid "Export EPUB" 68 | msgstr "Exporter l'EPUB" 69 | 70 | #: github_export/static/js/modules/github_export/templates.js:8 71 | msgid "Export unpacked EPUB" 72 | msgstr "Exporter l'EPUB décompressé" 73 | 74 | #: github_export/static/js/modules/github_export/templates.js:8 75 | msgid "Export HTML" 76 | msgstr "Exporter le HTML" 77 | 78 | #: github_export/static/js/modules/github_export/templates.js:8 79 | msgid "Export LaTeX" 80 | msgstr "Exporter LaTeX" 81 | 82 | #: github_export/static/js/modules/github_export/tools/commit_file.js:17 83 | msgid "Update from Fidus Writer" 84 | msgstr "Mise à jour de Fidus Writer" 85 | 86 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/locale/de/LC_MESSAGES/djangojs.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "MIME-Version: 1.0\n" 4 | "Content-Type: text/plain; charset=UTF-8\n" 5 | "Content-Transfer-Encoding: 8bit\n" 6 | "X-Generator: POEditor.com\n" 7 | "Project-Id-Version: Fidus Writer Github Export\n" 8 | "Language: de\n" 9 | 10 | #: github_export/static/js/modules/github_export/book_processor.js:20 11 | msgid "There is no github repository registered for the book:" 12 | msgstr "Für das Buch ist kein Github-Repository registriert:" 13 | 14 | #: github_export/static/js/modules/github_export/book_processor.js:27 15 | msgid "You do not have access to the repository:" 16 | msgstr "Sie haben keinen Zugriff auf das Repository:" 17 | 18 | #: github_export/static/js/modules/github_export/book_processor.js:31 19 | msgid "Book publishing to Github initiated." 20 | msgstr "Buchveröffentlichung auf Github eingeleitet." 21 | 22 | #: github_export/static/js/modules/github_export/book_processor.js:58 23 | msgid "Book already up to date in repository." 24 | msgstr "Buch ist bereits auf dem neuesten Stand im Repository." 25 | 26 | #: github_export/static/js/modules/github_export/book_processor.js:60 27 | msgid "Could not publish book to repository." 28 | msgstr "Buch konnte nicht im Repository veröffentlicht werden." 29 | 30 | #: github_export/static/js/modules/github_export/book_processor.js:62 31 | msgid "Could not publish some parts of book to repository." 32 | msgstr "Einige Teile des Buchs konnten nicht im Repository veröffentlicht werden." 33 | 34 | #: github_export/static/js/modules/github_export/book_processor.js:64 35 | msgid "Book published to repository successfully!" 36 | msgstr "Buch erfolgreich im Repository veröffentlicht!" 37 | 38 | #: github_export/static/js/modules/github_export/book_processor.js:66 39 | msgid "Book updated in repository successfully!" 40 | msgstr "Buch erfolgreich im Repository aktualisiert!" 41 | 42 | #: github_export/static/js/modules/github_export/books_overview.js:57 43 | msgid "Export to Github" 44 | msgstr "Nach Github exportieren" 45 | 46 | #: github_export/static/js/modules/github_export/books_overview.js:58 47 | msgid "Export selected to Github." 48 | msgstr "Ausgewählte nach Github exportieren." 49 | 50 | #: github_export/static/js/modules/github_export/books_overview.js:73 51 | msgid "Github" 52 | msgstr "Github" 53 | 54 | #: github_export/static/js/modules/github_export/books_overview.js:74 55 | msgid "Github related settings" 56 | msgstr "Github-bezogene Einstellungen" 57 | 58 | #: github_export/static/js/modules/github_export/templates.js:8 59 | msgid "Github repository" 60 | msgstr "Github-Repository" 61 | 62 | #: github_export/static/js/modules/github_export/templates.js:8 63 | msgid "Select github repository to export to" 64 | msgstr "Wählen Sie das Github-Repository aus, in das exportiert werden soll" 65 | 66 | #: github_export/static/js/modules/github_export/templates.js:8 67 | msgid "Export EPUB" 68 | msgstr "EPUB exportieren" 69 | 70 | #: github_export/static/js/modules/github_export/templates.js:8 71 | msgid "Export unpacked EPUB" 72 | msgstr "Entpackte EPUB exportieren" 73 | 74 | #: github_export/static/js/modules/github_export/templates.js:8 75 | msgid "Export HTML" 76 | msgstr "HTML exportieren" 77 | 78 | #: github_export/static/js/modules/github_export/templates.js:8 79 | msgid "Export LaTeX" 80 | msgstr "LaTeX exportieren" 81 | 82 | #: github_export/static/js/modules/github_export/tools/commit_file.js:17 83 | msgid "Update from Fidus Writer" 84 | msgstr "Update von Fidus Writer" 85 | 86 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/locale/es/LC_MESSAGES/djangojs.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "MIME-Version: 1.0\n" 4 | "Content-Type: text/plain; charset=UTF-8\n" 5 | "Content-Transfer-Encoding: 8bit\n" 6 | "X-Generator: POEditor.com\n" 7 | "Project-Id-Version: Fidus Writer Github Export\n" 8 | "Language: es\n" 9 | 10 | #: github_export/static/js/modules/github_export/book_processor.js:20 11 | msgid "There is no github repository registered for the book:" 12 | msgstr "No hay ningún repositorio de github registrado para el libro:" 13 | 14 | #: github_export/static/js/modules/github_export/book_processor.js:27 15 | msgid "You do not have access to the repository:" 16 | msgstr "No tienes acceso al repositorio:" 17 | 18 | #: github_export/static/js/modules/github_export/book_processor.js:31 19 | #, fuzzy 20 | msgid "Book publishing to Github initiated." 21 | msgstr "Se inició la publicación del libro en Github." 22 | 23 | #: github_export/static/js/modules/github_export/book_processor.js:58 24 | #, fuzzy 25 | msgid "Book already up to date in repository." 26 | msgstr "Libro ya está al día en repositorio." 27 | 28 | #: github_export/static/js/modules/github_export/book_processor.js:60 29 | msgid "Could not publish book to repository." 30 | msgstr "No se pudo publicar el libro en el repositorio." 31 | 32 | #: github_export/static/js/modules/github_export/book_processor.js:62 33 | msgid "Could not publish some parts of book to repository." 34 | msgstr "No se pudieron publicar algunas partes del libro en el repositorio." 35 | 36 | #: github_export/static/js/modules/github_export/book_processor.js:64 37 | msgid "Book published to repository successfully!" 38 | msgstr "¡Libro publicado en el repositorio con éxito!" 39 | 40 | #: github_export/static/js/modules/github_export/book_processor.js:66 41 | msgid "Book updated in repository successfully!" 42 | msgstr "¡Libro actualizado en el repositorio con éxito!" 43 | 44 | #: github_export/static/js/modules/github_export/books_overview.js:57 45 | msgid "Export to Github" 46 | msgstr "Exportar a Github" 47 | 48 | #: github_export/static/js/modules/github_export/books_overview.js:58 49 | #, fuzzy 50 | msgid "Export selected to Github." 51 | msgstr "Exportación seleccionados a Github." 52 | 53 | #: github_export/static/js/modules/github_export/books_overview.js:73 54 | msgid "Github" 55 | msgstr "Github" 56 | 57 | #: github_export/static/js/modules/github_export/books_overview.js:74 58 | msgid "Github related settings" 59 | msgstr "Configuraciones relacionadas con Github" 60 | 61 | #: github_export/static/js/modules/github_export/templates.js:8 62 | msgid "Github repository" 63 | msgstr "Repositorio de Github" 64 | 65 | #: github_export/static/js/modules/github_export/templates.js:8 66 | msgid "Select github repository to export to" 67 | msgstr "Seleccione el repositorio de github para exportar" 68 | 69 | #: github_export/static/js/modules/github_export/templates.js:8 70 | msgid "Export EPUB" 71 | msgstr "Exportar EPUB" 72 | 73 | #: github_export/static/js/modules/github_export/templates.js:8 74 | msgid "Export unpacked EPUB" 75 | msgstr "Exportar EPUB descomprimido" 76 | 77 | #: github_export/static/js/modules/github_export/templates.js:8 78 | msgid "Export HTML" 79 | msgstr "Exportar HTML" 80 | 81 | #: github_export/static/js/modules/github_export/templates.js:8 82 | msgid "Export LaTeX" 83 | msgstr "Exportar LaTeX" 84 | 85 | #: github_export/static/js/modules/github_export/tools/commit_file.js:17 86 | msgid "Update from Fidus Writer" 87 | msgstr "Actualización desde Fidus Writer" 88 | 89 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/static/js/modules/gitrepo_export/gitlab/book_exporters.js: -------------------------------------------------------------------------------- 1 | import {DOCXBookExporter} from "../../books/exporter/docx" 2 | import {EpubBookExporter} from "../../books/exporter/epub" 3 | import {HTMLBookExporter} from "../../books/exporter/html" 4 | import {LatexBookExporter} from "../../books/exporter/latex" 5 | import {ODTBookExporter} from "../../books/exporter/odt" 6 | import {zipToBlobs} from "./tools" 7 | 8 | export class EpubBookGitlabExporter extends EpubBookExporter { 9 | constructor(schema, csl, bookStyles, book, user, docList, updated, repo) { 10 | super(schema, csl, bookStyles, book, user, docList, updated) 11 | this.repo = repo 12 | } 13 | 14 | download(blob) { 15 | return Promise.resolve({ 16 | "book.epub": blob 17 | }) 18 | } 19 | } 20 | 21 | export class UnpackedEpubBookGitlabExporter extends EpubBookExporter { 22 | constructor(schema, csl, bookStyles, book, user, docList, updated, repo) { 23 | super(schema, csl, bookStyles, book, user, docList, updated) 24 | this.repo = repo 25 | } 26 | 27 | createZip() { 28 | return zipToBlobs( 29 | this.outputList, 30 | this.binaryFiles, 31 | this.includeZips, 32 | "epub/" 33 | ) 34 | } 35 | } 36 | 37 | export class HTMLBookGitlabExporter extends HTMLBookExporter { 38 | constructor(schema, csl, bookStyles, book, user, docList, updated, repo) { 39 | super(schema, csl, bookStyles, book, user, docList, updated) 40 | this.repo = repo 41 | } 42 | 43 | createZip() { 44 | return zipToBlobs( 45 | this.outputList, 46 | this.binaryFiles, 47 | this.includeZips, 48 | "html/" 49 | ) 50 | } 51 | } 52 | 53 | export class SingleFileHTMLBookGitlabExporter extends HTMLBookExporter { 54 | constructor(schema, csl, bookStyles, book, user, docList, updated, repo) { 55 | super(schema, csl, bookStyles, book, user, docList, updated, false) 56 | this.repo = repo 57 | } 58 | 59 | createZip() { 60 | return zipToBlobs( 61 | this.outputList, 62 | this.binaryFiles, 63 | this.includeZips, 64 | "uhtml/" 65 | ) 66 | } 67 | } 68 | 69 | export class LatexBookGitlabExporter extends LatexBookExporter { 70 | constructor(schema, book, user, docList, updated, repo) { 71 | super(schema, book, user, docList, updated) 72 | this.repo = repo 73 | } 74 | 75 | createZip() { 76 | return zipToBlobs(this.textFiles, this.httpFiles, [], "latex/") 77 | } 78 | } 79 | 80 | export class DOCXBookGitlabExporter extends DOCXBookExporter { 81 | constructor(schema, csl, book, user, docList, updated, repo) { 82 | super(schema, csl, book, user, docList, updated) 83 | this.repo = repo 84 | } 85 | 86 | download(blob) { 87 | return Promise.resolve({ 88 | "book.docx": blob 89 | }) 90 | } 91 | } 92 | 93 | export class ODTBookGitlabExporter extends ODTBookExporter { 94 | constructor(schema, csl, book, user, docList, updated, repo) { 95 | super(schema, csl, book, user, docList, updated) 96 | this.repo = repo 97 | } 98 | 99 | download(blob) { 100 | return Promise.resolve({ 101 | "book.odt": blob 102 | }) 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/static/js/modules/gitrepo_export/github/tools/commit_file.js: -------------------------------------------------------------------------------- 1 | import {getCookie, getJson} from "../../../common" 2 | import {gitHashObject, readBlobPromise} from "../../tools" 3 | 4 | export function commitFile( 5 | repo, 6 | blob, 7 | filename, 8 | parentDir = "", 9 | repoDirCache = {} 10 | ) { 11 | const dirUrl = 12 | `/api/gitrepo_export/proxy_github/repos/${repo.name}/contents/${parentDir}`.replace( 13 | /\/\//, 14 | "/" 15 | ) 16 | const getDirJsonPromise = repoDirCache[dirUrl] 17 | ? Promise.resolve(repoDirCache[dirUrl]) 18 | : getJson(dirUrl) 19 | .then(json => { 20 | repoDirCache[dirUrl] = json 21 | return Promise.resolve(json) 22 | }) 23 | .catch(error => { 24 | if (error.status === 302) { 25 | // Redirect - which means the directory does not exist. 26 | return Promise.resolve(false) 27 | } 28 | throw error 29 | }) 30 | const csrfToken = getCookie("csrftoken") 31 | return Promise.resolve(getDirJsonPromise) 32 | .then(json => { 33 | const fileEntry = Array.isArray(json) 34 | ? json.find(entry => entry.name === filename) 35 | : false 36 | const commitData = { 37 | encoding: "base64" 38 | } 39 | return readBlobPromise(blob).then(content => { 40 | commitData.content = content 41 | if (!fileEntry) { 42 | return Promise.resolve(commitData) 43 | } 44 | const binaryString = atob(commitData.content) 45 | if (fileEntry.size !== binaryString.length) { 46 | return Promise.resolve(commitData) 47 | } 48 | return gitHashObject( 49 | binaryString, 50 | // UTF-8 files seem to have no type set. 51 | // Not sure if this is actually a viable way to distinguish between utf-8 and binary files. 52 | !blob.type.length 53 | ).then(sha => { 54 | if (sha === fileEntry.sha) { 55 | return Promise.resolve(304) 56 | } else { 57 | return Promise.resolve(commitData) 58 | } 59 | }) 60 | }) 61 | }) 62 | .then(commitData => { 63 | if (!commitData || commitData === 304) { 64 | return Promise.resolve(304) 65 | } 66 | return fetch( 67 | `/api/gitrepo_export/proxy_github/repos/${repo.name}/git/blobs`.replace( 68 | /\/\//, 69 | "/" 70 | ), 71 | { 72 | method: "POST", 73 | headers: { 74 | "X-CSRFToken": csrfToken 75 | }, 76 | credentials: "include", 77 | body: JSON.stringify(commitData) 78 | } 79 | ).then(response => { 80 | if (response.ok) { 81 | return response.json().then(json => { 82 | const treeObject = { 83 | path: `${parentDir}${filename}`, 84 | sha: json.sha, 85 | mode: "100644", 86 | type: "blob" 87 | } 88 | return treeObject 89 | }) 90 | } else { 91 | return Promise.resolve(400) 92 | } 93 | }) 94 | }) 95 | .catch(_error => { 96 | return Promise.resolve(400) 97 | }) 98 | } 99 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/static/js/modules/gitrepo_export/github/tools/commit_zip_contents.js: -------------------------------------------------------------------------------- 1 | import {get, getCookie} from "../../../common" 2 | import {commitFile} from "./commit_file" 3 | import {promiseChain} from "./promise_chain" 4 | 5 | export function commitZipContents( 6 | repo, 7 | outputList, 8 | binaryFiles, 9 | includeZips, 10 | parentDir = "" 11 | ) { 12 | const csrfToken = getCookie("csrftoken") 13 | const repoDirCache = {} 14 | const textCommitFunctions = outputList.map(file => { 15 | const blob = new Blob([file.contents]) 16 | const filepathParts = file.filename.split("/") 17 | const filename = filepathParts.pop() 18 | const subDir = `${parentDir}${filepathParts.join("/")}/`.replace( 19 | /\/\//, 20 | "/" 21 | ) 22 | return () => commitFile(repo, blob, filename, subDir, repoDirCache) 23 | }) 24 | const commitBinaries = binaryFiles.map(file => 25 | get(file.url) 26 | .then(response => response.blob()) 27 | .then(blob => { 28 | const filepathParts = file.filename.split("/") 29 | const filename = filepathParts.pop() 30 | const subDir = `${parentDir}${filepathParts.join( 31 | "/" 32 | )}/`.replace(/\/\//, "/") 33 | return () => 34 | commitFile(repo, blob, filename, subDir, repoDirCache) 35 | }) 36 | ) 37 | const commitZips = import("jszip").then(({default: JSZip}) => { 38 | return includeZips.map(zipFile => 39 | get(zipFile.url) 40 | .then(response => response.blob()) 41 | .then(blob => { 42 | const zipfs = new JSZip() 43 | return zipfs.loadAsync(blob).then(() => { 44 | const files = [] 45 | zipfs.forEach(file => files.push(file)) 46 | return Promise.all( 47 | files.map(filepath => 48 | zipfs.files[filepath].async("blob") 49 | ) 50 | ).then(blobs => 51 | blobs.map((blob, index) => { 52 | const filepath = files[index] 53 | const filepathParts = filepath.split("/") 54 | const filename = filepathParts.pop() 55 | const dir = zipFile.directory 56 | ? [zipFile.directory].concat(filepathParts) 57 | : filepathParts 58 | const subDir = `${parentDir}${dir.join( 59 | "/" 60 | )}/`.replace(/\/\//, "/") 61 | return () => 62 | commitFile( 63 | repo, 64 | blob, 65 | filename, 66 | subDir, 67 | repoDirCache, 68 | csrfToken 69 | ) 70 | }) 71 | ) 72 | }) 73 | }) 74 | ) 75 | }) 76 | return Promise.resolve(commitZips) 77 | .then(zips => 78 | Promise.all(commitBinaries).then(binaryCommitFunctions => 79 | Promise.all(zips).then(zipCommitFunctions => 80 | textCommitFunctions 81 | .concat(binaryCommitFunctions) 82 | .concat(zipCommitFunctions) 83 | .flat() 84 | ) 85 | ) 86 | ) 87 | .then(commitFunctions => promiseChain(commitFunctions)) 88 | } 89 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/static/js/modules/gitrepo_export/github/book_exporters.js: -------------------------------------------------------------------------------- 1 | import {DOCXBookExporter} from "../../books/exporter/docx" 2 | import {EpubBookExporter} from "../../books/exporter/epub" 3 | import {HTMLBookExporter} from "../../books/exporter/html" 4 | import {LatexBookExporter} from "../../books/exporter/latex" 5 | import {ODTBookExporter} from "../../books/exporter/odt" 6 | import {commitFile, commitZipContents} from "./tools" 7 | 8 | export class EpubBookGithubExporter extends EpubBookExporter { 9 | constructor(schema, csl, bookStyles, book, user, docList, updated, repo) { 10 | super(schema, csl, bookStyles, book, user, docList, updated) 11 | this.repo = repo 12 | } 13 | 14 | download(blob) { 15 | return () => 16 | commitFile(this.repo, blob, "book.epub").then(response => [ 17 | response 18 | ]) 19 | } 20 | } 21 | 22 | export class UnpackedEpubBookGithubExporter extends EpubBookExporter { 23 | constructor(schema, csl, bookStyles, book, user, docList, updated, repo) { 24 | super(schema, csl, bookStyles, book, user, docList, updated) 25 | this.repo = repo 26 | } 27 | 28 | createZip() { 29 | return () => 30 | commitZipContents( 31 | this.repo, 32 | this.outputList, 33 | this.binaryFiles, 34 | this.includeZips, 35 | "epub/" 36 | ) 37 | } 38 | } 39 | 40 | export class HTMLBookGithubExporter extends HTMLBookExporter { 41 | constructor(schema, csl, bookStyles, book, user, docList, updated, repo) { 42 | super(schema, csl, bookStyles, book, user, docList, updated) 43 | this.repo = repo 44 | } 45 | 46 | createZip() { 47 | return () => 48 | commitZipContents( 49 | this.repo, 50 | this.outputList, 51 | this.binaryFiles, 52 | this.includeZips, 53 | "html/" 54 | ) 55 | } 56 | } 57 | 58 | export class SingleFileHTMLBookGithubExporter extends HTMLBookExporter { 59 | constructor(schema, csl, bookStyles, book, user, docList, updated, repo) { 60 | super(schema, csl, bookStyles, book, user, docList, updated, false) 61 | this.repo = repo 62 | } 63 | 64 | createZip() { 65 | return () => 66 | commitZipContents( 67 | this.repo, 68 | this.outputList, 69 | this.binaryFiles, 70 | this.includeZips, 71 | "uhtml/" 72 | ) 73 | } 74 | } 75 | 76 | export class LatexBookGithubExporter extends LatexBookExporter { 77 | constructor(schema, book, user, docList, updated, repo) { 78 | super(schema, book, user, docList, updated) 79 | this.repo = repo 80 | } 81 | 82 | createZip() { 83 | return () => 84 | commitZipContents( 85 | this.repo, 86 | this.textFiles, 87 | this.httpFiles, 88 | [], 89 | "latex/" 90 | ) 91 | } 92 | } 93 | 94 | export class DOCXBookGithubExporter extends DOCXBookExporter { 95 | constructor(schema, csl, book, user, docList, updated, repo) { 96 | super(schema, csl, book, user, docList, updated) 97 | this.repo = repo 98 | } 99 | 100 | download(blob) { 101 | return () => 102 | commitFile(this.repo, blob, "book.docx").then(response => [ 103 | response 104 | ]) 105 | } 106 | } 107 | 108 | export class ODTBookGithubExporter extends ODTBookExporter { 109 | constructor(schema, csl, book, user, docList, updated, repo) { 110 | super(schema, csl, book, user, docList, updated) 111 | this.repo = repo 112 | } 113 | 114 | download(blob) { 115 | return () => 116 | commitFile(this.repo, blob, "book.odt").then(response => [response]) 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/static/js/modules/gitrepo_export/templates.js: -------------------------------------------------------------------------------- 1 | import {escapeText} from "../common" 2 | 3 | const REPO_TYPES = { 4 | github: "GitHub", 5 | gitlab: "GitLab" 6 | } 7 | 8 | function repoName(name, type, userReposMultitype) { 9 | if (userReposMultitype) { 10 | return `${REPO_TYPES[type]}: ${escapeText(name)}` 11 | } 12 | return escapeText(name) 13 | } 14 | 15 | export const repoSelectorTemplate = ({ 16 | book, 17 | bookRepos, 18 | userRepos, 19 | userReposMultitype 20 | }) => { 21 | const bookRepo = bookRepos[book.id] 22 | return ` 23 | 24 |

${gettext("Git repository")}

25 | 26 | 27 |
28 | 57 |
58 |
59 | 60 | 61 | 64 | 65 | 66 | 67 | 68 | 69 |

${gettext("Export EPUB")}

70 | 71 | 72 | 75 | 76 | 77 | 78 | 79 |

${gettext("Export unpacked EPUB")}

80 | 81 | 82 | 85 | 86 | 87 | 88 | 89 |

${gettext("Export HTML")}

90 | 91 | 92 | 95 | 96 | 97 | 98 | 99 |

${gettext("Export Unified HTML")}

100 | 101 | 102 | 105 | 106 | 107 | 108 | 109 |

${gettext("Export LaTeX")}

110 | 111 | 112 | 115 | 116 | 117 | 118 | 119 |

${gettext("Export ODT")}

120 | 121 | 122 | 127 | 128 | 129 | 130 | 131 |

${gettext("Export DOCX")}

132 | 133 | 134 | 139 | 140 | ` 141 | } 142 | -------------------------------------------------------------------------------- /lint/django_import_resolver.js: -------------------------------------------------------------------------------- 1 | const path = require("path") 2 | const fs = require("fs") 3 | const acorn = require("acorn") 4 | const {execSync} = require("child_process") 5 | 6 | const EXCEPTIONS = ["../../../mathlive/opf_includes"] 7 | 8 | function getFidusWriterPath() { 9 | try { 10 | const fwPath = execSync( 11 | "python -c \"import fiduswriter; print(next(filter(lambda path: '/site-packages/' in path, fiduswriter.__path__), ''))\"" 12 | ) 13 | .toString() 14 | .trim() 15 | if (fwPath) { 16 | return fwPath 17 | } 18 | throw new Error("Fidus Writer not found") 19 | } catch (error) { 20 | console.error( 21 | "Failed to find Fidus Writer installation:", 22 | error.message 23 | ) 24 | process.exit(1) 25 | } 26 | } 27 | 28 | function isFile(file) { 29 | let stat 30 | try { 31 | stat = fs.statSync(file) 32 | } catch (e) { 33 | if (e && (e.code === "ENOENT" || e.code === "ENOTDIR")) { 34 | return false 35 | } 36 | throw e 37 | } 38 | return stat.isFile() || stat.isFIFO() 39 | } 40 | 41 | function getAppsPaths(rootDir) { 42 | const appsPaths = [] 43 | const subdirs = fs.readdirSync(rootDir, {withFileTypes: true}) 44 | subdirs.forEach(subdir => { 45 | if (subdir.isDirectory()) { 46 | const staticPath = path.join(rootDir, subdir.name, "static") 47 | if ( 48 | fs.existsSync(staticPath) && 49 | fs.lstatSync(staticPath).isDirectory() 50 | ) { 51 | appsPaths.push(path.join(rootDir, subdir.name)) 52 | } 53 | } 54 | }) 55 | return appsPaths 56 | } 57 | 58 | function resolveFilelocation(source, file, appsPaths) { 59 | const returnValue = {found: false, path: null} 60 | const fullPath = path.resolve(path.dirname(file), source) 61 | 62 | if (fullPath.includes("/plugins/")) { 63 | returnValue.found = true 64 | returnValue.path = null 65 | return returnValue 66 | } 67 | 68 | // Check in plugin and fidus writer apps 69 | appsPaths.find(appPath => { 70 | const resolvedPath = fullPath.replace( 71 | /.*\/static\/js\//g, 72 | `${appPath}/static/js/` 73 | ) 74 | if (isFile(`${resolvedPath}.js`)) { 75 | returnValue.path = `${resolvedPath}.js` 76 | returnValue.found = true 77 | return true 78 | } 79 | if (isFile(`${resolvedPath}/index.js`)) { 80 | returnValue.path = `${resolvedPath}/index.js` 81 | returnValue.found = true 82 | return true 83 | } 84 | 85 | return false 86 | }) 87 | 88 | return returnValue 89 | } 90 | 91 | function checkExports(filePath, importedNames, sourcePath) { 92 | const content = fs.readFileSync(filePath, "utf-8") 93 | const ast = acorn.parse(content, { 94 | sourceType: "module", 95 | ecmaVersion: "latest" 96 | }) 97 | 98 | const exportedNames = new Set() 99 | 100 | ast.body.forEach(node => { 101 | if (node.type === "ExportNamedDeclaration") { 102 | if (node.declaration) { 103 | if (node.declaration.id) { 104 | exportedNames.add(node.declaration.id.name) 105 | } else if (node.declaration.declarations) { 106 | node.declaration.declarations.forEach(decl => { 107 | if (decl.id && decl.id.name) { 108 | exportedNames.add(decl.id.name) 109 | } 110 | }) 111 | } 112 | } 113 | if (node.specifiers) { 114 | node.specifiers.forEach(spec => { 115 | exportedNames.add(spec.exported.name) 116 | }) 117 | } 118 | } else if (node.type === "ExportDefaultDeclaration") { 119 | exportedNames.add("default") 120 | } 121 | }) 122 | 123 | importedNames.forEach(name => { 124 | if (!exportedNames.has(name)) { 125 | console.error( 126 | `Unresolved export: ${name} not found in ${filePath}, imported in ${sourcePath}` 127 | ) 128 | process.exit(1) 129 | } 130 | }) 131 | } 132 | 133 | function checkImports(file, appsPaths) { 134 | const content = fs.readFileSync(file, "utf-8") 135 | const importRegex = 136 | /import\s+(?:(\*\s+as\s+\w+)|(\w+)|(\{[^}]+\}))\s+from\s+['"](.*)['"]/g 137 | let match 138 | while ((match = importRegex.exec(content)) !== null) { 139 | const source = match[4] 140 | // Skip non-relative imports 141 | if (!source.startsWith(".") && !source.startsWith("..")) { 142 | continue 143 | } 144 | if (EXCEPTIONS.includes(source)) { 145 | continue 146 | } 147 | const result = resolveFilelocation(source, file, appsPaths) 148 | if (!result.found) { 149 | console.error(`Unresolved import: ${source} in file ${file}`) 150 | process.exit(1) 151 | } 152 | 153 | const importedNames = [] 154 | if (match[1]) { 155 | // import * as name 156 | importedNames.push("*") 157 | } else if (match[2]) { 158 | // import name 159 | importedNames.push("default") 160 | } else if (match[3]) { 161 | // import { name1, name2 } 162 | const names = match[3] 163 | .replace(/[{}]/g, "") 164 | .split(",") 165 | .map(name => name.trim()) 166 | importedNames.push(...names) 167 | } 168 | if (!result.path) { 169 | // Plugin - final path cannot be checked yet. 170 | return 171 | } 172 | checkExports(result.path, importedNames, file) 173 | } 174 | } 175 | 176 | const pluginPath = path.resolve(__dirname, "../fiduswriter") 177 | const pluginAppsPaths = getAppsPaths(pluginPath) 178 | 179 | const fidusWriterPath = getFidusWriterPath() 180 | const fidusWriterAppsPaths = getAppsPaths(fidusWriterPath) 181 | 182 | const appsPaths = pluginAppsPaths.concat(fidusWriterAppsPaths) 183 | 184 | const files = process.argv.slice(2) 185 | files.forEach(file => checkImports(file, appsPaths)) 186 | -------------------------------------------------------------------------------- /biome.json: -------------------------------------------------------------------------------- 1 | { 2 | "formatter": { 3 | "enabled": true, 4 | "useEditorconfig": true, 5 | "formatWithErrors": false, 6 | "indentStyle": "space", 7 | "indentWidth": 4, 8 | "lineEnding": "lf", 9 | "lineWidth": 80, 10 | "attributePosition": "auto", 11 | "bracketSpacing": true, 12 | "ignore": [ 13 | "**/.transpile-cache/", 14 | "**/venv/", 15 | "**/static-transpile/", 16 | "**/static-libs/", 17 | "**/static-collected/", 18 | "**/node-modules/", 19 | "**/testing/", 20 | "**/.eslintrc.mjs", 21 | "**/*.json", 22 | "**/*.html", 23 | "**/.direnv", 24 | "**/venv", 25 | "**/.transpile", 26 | "**/.babelrc", 27 | "**/sw-template.js" 28 | ] 29 | }, 30 | "linter": { 31 | "enabled": true, 32 | "rules": { 33 | "recommended": false, 34 | "complexity": { 35 | "noExtraBooleanCast": "error", 36 | "noMultipleSpacesInRegularExpressionLiterals": "error", 37 | "noUselessCatch": "off", 38 | "noUselessConstructor": "off", 39 | "noUselessLabel": "error", 40 | "noUselessLoneBlockStatements": "error", 41 | "noUselessRename": "error", 42 | "noUselessStringConcat": "error", 43 | "noUselessTernary": "off", 44 | "noUselessUndefinedInitialization": "error", 45 | "noVoid": "error", 46 | "noWith": "error", 47 | "useLiteralKeys": "off" 48 | }, 49 | "correctness": { 50 | "noConstAssign": "error", 51 | "noConstantCondition": "error", 52 | "noEmptyCharacterClassInRegex": "error", 53 | "noEmptyPattern": "error", 54 | "noGlobalObjectCalls": "error", 55 | "noInnerDeclarations": "error", 56 | "noInvalidConstructorSuper": "error", 57 | "noInvalidUseBeforeDeclaration": "off", 58 | "noNewSymbol": "error", 59 | "noNonoctalDecimalEscape": "error", 60 | "noPrecisionLoss": "error", 61 | "noSelfAssign": "error", 62 | "noSetterReturn": "error", 63 | "noSwitchDeclarations": "error", 64 | "noUndeclaredVariables": "error", 65 | "noUnreachable": "error", 66 | "noUnreachableSuper": "error", 67 | "noUnsafeFinally": "error", 68 | "noUnsafeOptionalChaining": "error", 69 | "noUnusedLabels": "error", 70 | "noUnusedVariables": "error", 71 | "useArrayLiterals": "error", 72 | "useIsNan": "error", 73 | "useValidForDirection": "error", 74 | "useYield": "error" 75 | }, 76 | "security": { "noGlobalEval": "error" }, 77 | "style": { 78 | "noArguments": "off", 79 | "noCommaOperator": "error", 80 | "noNegationElse": "off", 81 | "noParameterAssign": "off", 82 | "noRestrictedGlobals": { "level": "error", "options": {} }, 83 | "noVar": "error", 84 | "noYodaExpression": "off", 85 | "useBlockStatements": "error", 86 | "useCollapsedElseIf": "off", 87 | "useConsistentBuiltinInstantiation": "error", 88 | "useConst": "warn", 89 | "useDefaultSwitchClause": "off", 90 | "useNumericLiterals": "error", 91 | "useShorthandAssign": "off", 92 | "useSingleVarDeclarator": "off", 93 | "useTemplate": "off" 94 | }, 95 | "suspicious": { 96 | "noAsyncPromiseExecutor": "error", 97 | "noCatchAssign": "error", 98 | "noClassAssign": "error", 99 | "noCompareNegZero": "error", 100 | "noControlCharactersInRegex": "off", 101 | "noDebugger": "error", 102 | "noDoubleEquals": "off", 103 | "noDuplicateCase": "error", 104 | "noDuplicateClassMembers": "error", 105 | "noDuplicateObjectKeys": "error", 106 | "noDuplicateParameters": "error", 107 | "noEmptyBlockStatements": "off", 108 | "noFallthroughSwitchClause": "error", 109 | "noFunctionAssign": "error", 110 | "noGlobalAssign": "error", 111 | "noImportAssign": "error", 112 | "noLabelVar": "error", 113 | "noMisleadingCharacterClass": "error", 114 | "noPrototypeBuiltins": "off", 115 | "noRedeclare": "error", 116 | "noSelfCompare": "error", 117 | "noShadowRestrictedNames": "error", 118 | "noSparseArray": "error", 119 | "noUnsafeNegation": "error", 120 | "useAwait": "error", 121 | "useGetterReturn": "error", 122 | "useValidTypeof": "error" 123 | } 124 | }, 125 | "ignore": [ 126 | "**/.transpile-cache/", 127 | "**/venv/", 128 | "**/static-transpile/", 129 | "**/static-libs/", 130 | "**/static-collected/", 131 | "**/testing/", 132 | "**/manifest.json", 133 | "**/sw-template.js" 134 | ] 135 | }, 136 | "javascript": { 137 | "formatter": { 138 | "jsxQuoteStyle": "double", 139 | "quoteProperties": "asNeeded", 140 | "trailingCommas": "none", 141 | "semicolons": "asNeeded", 142 | "indentWidth": 4, 143 | "arrowParentheses": "asNeeded", 144 | "bracketSameLine": true, 145 | "quoteStyle": "double", 146 | "attributePosition": "auto", 147 | "bracketSpacing": false 148 | }, 149 | "globals": [ 150 | "settings_MEDIA_MAX_SIZE", 151 | "settings_SOCIALACCOUNT_OPEN", 152 | "settings_REGISTRATION_OPEN", 153 | "gettext", 154 | "interpolate", 155 | "settings_USE_SERVICE_WORKER", 156 | "transpile_VERSION", 157 | "settings_TEST_SERVER", 158 | "settings_DEBUG", 159 | "settings_SOURCE_MAPS", 160 | "settings_STATIC_URL", 161 | "settings_PASSWORD_LOGIN", 162 | "process", 163 | "staticUrl", 164 | "settings_CONTACT_EMAIL", 165 | "settings_IS_FREE", 166 | "settings_FOOTER_LINKS", 167 | "settings_BRANDING_LOGO" 168 | ] 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/views.py: -------------------------------------------------------------------------------- 1 | from django.contrib.auth.decorators import login_required 2 | from django.views.decorators.http import ( 3 | require_GET, 4 | require_POST, 5 | require_http_methods, 6 | ) 7 | from django.http import JsonResponse, HttpResponseForbidden, HttpResponse 8 | from httpx import HTTPError 9 | from base.decorators import ajax_required 10 | from django.db.models import Q 11 | from allauth.socialaccount.models import SocialToken 12 | 13 | from book.models import Book 14 | from . import models 15 | 16 | from .helpers import github, gitlab 17 | 18 | 19 | @login_required 20 | @ajax_required 21 | @require_GET 22 | def get_book_repos(request): 23 | response = {} 24 | status = 200 25 | book_repos = models.BookRepository.objects.filter( 26 | Q(book__owner=request.user) 27 | | Q( 28 | book__bookaccessright__holder_id=request.user.id, 29 | book__bookaccessright__holder_type__model="user", 30 | ) 31 | ).distinct() 32 | response["repos"] = {} 33 | for repo in book_repos: 34 | response["repos"][repo.book.id] = { 35 | "repo_id": repo.repo_id, 36 | "repo_name": repo.repo_name, 37 | "repo_type": repo.repo_type, 38 | "export_epub": repo.export_epub, 39 | "export_unpacked_epub": repo.export_unpacked_epub, 40 | "export_html": repo.export_html, 41 | "export_unified_html": repo.export_unified_html, 42 | "export_latex": repo.export_latex, 43 | "export_odt": repo.export_odt, 44 | "export_docx": repo.export_docx, 45 | } 46 | return JsonResponse(response, status=status) 47 | 48 | 49 | @login_required 50 | @ajax_required 51 | @require_POST 52 | def update_book_repo(request): 53 | book_id = request.POST["book_id"] 54 | book = Book.objects.filter(id=book_id).first() 55 | if not book or ( 56 | book.owner != request.user 57 | and not book.bookaccessright_set.filter( 58 | holder_id=request.user.id, 59 | holder_type__model="user", 60 | rights="write", 61 | ).exists() 62 | ): 63 | return HttpResponseForbidden() 64 | models.BookRepository.objects.filter(book_id=book_id).delete() 65 | repo_id = request.POST["repo_id"] 66 | if repo_id == 0: 67 | status = 200 68 | else: 69 | models.BookRepository.objects.create( 70 | book_id=book_id, 71 | repo_id=repo_id, 72 | repo_name=request.POST["repo_name"], 73 | repo_type=request.POST["repo_type"], 74 | export_epub=request.POST["export_epub"] == "true", 75 | export_unpacked_epub=request.POST["export_unpacked_epub"] 76 | == "true", 77 | export_html=request.POST["export_html"] == "true", 78 | export_unified_html=request.POST["export_unified_html"] == "true", 79 | export_latex=request.POST["export_latex"] == "true", 80 | export_docx=request.POST["export_docx"] == "true", 81 | export_odt=request.POST["export_odt"] == "true", 82 | ) 83 | status = 201 84 | return HttpResponse(status=status) 85 | 86 | 87 | @login_required 88 | @require_GET 89 | async def get_git_repos(request, reload=False): 90 | request_user = await request.auser() 91 | social_tokens = { 92 | "github": await SocialToken.objects.filter( 93 | account__user=request_user, account__provider="github" 94 | ).afirst(), 95 | "gitlab": await SocialToken.objects.filter( 96 | account__user=request_user, account__provider="gitlab" 97 | ).afirst(), 98 | } 99 | 100 | if not social_tokens["github"] and not social_tokens["gitlab"]: 101 | return HttpResponseForbidden() 102 | repo_info = await models.RepoInfo.objects.filter( 103 | user=request_user 104 | ).afirst() 105 | if repo_info: 106 | if reload: 107 | await repo_info.adelete() 108 | else: 109 | return JsonResponse({"repos": repo_info.content}, status=200) 110 | repos = [] 111 | try: 112 | if social_tokens["github"]: 113 | repos += await github.get_repos(social_tokens["github"]) 114 | if social_tokens["gitlab"]: 115 | repos += await gitlab.get_repos(request, social_tokens["gitlab"]) 116 | except HTTPError as e: 117 | if e.response.code == 404: 118 | # We remove the 404 response so it will not show up as an 119 | # error in the browser 120 | pass 121 | else: 122 | return HttpResponse(e.response.text, status=e.response.status_code) 123 | return [] 124 | except Exception as e: 125 | return HttpResponse("Error: %s" % e, status=500) 126 | repo_info, created = await models.RepoInfo.objects.aget_or_create( 127 | user=request_user 128 | ) 129 | repo_info.content = repos 130 | await repo_info.asave() 131 | return JsonResponse({"repos": repos}, status=200) 132 | 133 | 134 | @login_required 135 | @require_http_methods(["GET", "POST", "PATCH"]) 136 | async def proxy_github(request, path): 137 | request_user = await request.auser() 138 | try: 139 | response = await github.proxy( 140 | path, 141 | request_user, 142 | request.META["QUERY_STRING"], 143 | request.body, 144 | request.method, 145 | ) 146 | except HTTPError as e: 147 | if e.response.code == 404: 148 | # We remove the 404 response so it will not show up as an 149 | # error in the browser 150 | return HttpResponse("[]", status=200) 151 | else: 152 | return HttpResponse(e.response.text, status=e.response.status_code) 153 | except Exception as e: 154 | return HttpResponse("Error: %s" % e, status=500) 155 | else: 156 | return HttpResponse(response.text, status=response.status_code) 157 | 158 | 159 | @login_required 160 | @require_http_methods(["GET", "POST", "PATCH"]) 161 | async def proxy_gitlab(request, path): 162 | request_user = await request.auser() 163 | try: 164 | response = await gitlab.proxy( 165 | request, 166 | path, 167 | request_user, 168 | request.META["QUERY_STRING"], 169 | request.body, 170 | request.method, 171 | ) 172 | except HTTPError as e: 173 | if e.response.code == 404: 174 | # We remove the 404 response so it will not show up as an 175 | # error in the browser 176 | return HttpResponse("[]", status=200) 177 | else: 178 | return HttpResponse(e.response.text, status=e.response.status_code) 179 | except Exception as e: 180 | return HttpResponse("Error: %s" % e, status=500) 181 | else: 182 | return HttpResponse(response.text, status=response.status_code) 183 | 184 | 185 | @login_required 186 | @require_GET 187 | async def get_gitlab_repo(request, id): 188 | request_user = await request.auser() 189 | try: 190 | files = await gitlab.get_repo(request, id, request_user) 191 | except HTTPError as e: 192 | return HttpResponse(e.response.text, status=e.response.status_code) 193 | except Exception as e: 194 | return HttpResponse("Error: %s" % e, status=500) 195 | else: 196 | return JsonResponse({"files": files}, status=200) 197 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/static/js/modules/gitrepo_export/gitlab/book_processor.js: -------------------------------------------------------------------------------- 1 | import {Dialog, addAlert, escapeText} from "../../common" 2 | import { 3 | DOCXBookGitlabExporter, 4 | EpubBookGitlabExporter, 5 | HTMLBookGitlabExporter, 6 | LatexBookGitlabExporter, 7 | ODTBookGitlabExporter, 8 | SingleFileHTMLBookGitlabExporter, 9 | UnpackedEpubBookGitlabExporter 10 | } from "./book_exporters" 11 | import {commitFiles} from "./tools" 12 | 13 | export class GitlabBookProcessor { 14 | constructor(app, booksOverview, book, bookRepo, userRepo) { 15 | this.app = app 16 | this.booksOverview = booksOverview 17 | this.book = book 18 | this.bookRepo = bookRepo 19 | this.userRepo = userRepo 20 | } 21 | 22 | init() { 23 | return this.getCommitMessage() 24 | .then(commitMessage => this.publishBook(commitMessage)) 25 | .catch(() => {}) 26 | } 27 | 28 | getCommitMessage() { 29 | return new Promise((resolve, reject) => { 30 | const buttons = [ 31 | { 32 | text: gettext("Submit"), 33 | classes: "fw-dark", 34 | click: () => { 35 | const commitMessage = 36 | dialog.dialogEl.querySelector(".commit-message") 37 | .value || gettext("Update from Fidus Writer") 38 | dialog.close() 39 | resolve(commitMessage) 40 | } 41 | }, 42 | { 43 | type: "cancel", 44 | click: () => { 45 | dialog.close() 46 | reject() 47 | } 48 | } 49 | ] 50 | 51 | const dialog = new Dialog({ 52 | title: gettext("Commit message"), 53 | height: 150, 54 | body: `

55 | ${gettext("Updating")}: ${escapeText(this.book.title)} 56 | 59 |

`, 60 | buttons 61 | }) 62 | dialog.open() 63 | }) 64 | } 65 | 66 | publishBook(commitMessage) { 67 | addAlert("info", gettext("Book publishing to GitLab initiated.")) 68 | 69 | const fileGetters = [] 70 | 71 | if (this.bookRepo.export_epub) { 72 | const epubExporter = new EpubBookGitlabExporter( 73 | this.booksOverview.schema, 74 | this.booksOverview.app.csl, 75 | this.booksOverview.styles, 76 | this.book, 77 | this.booksOverview.user, 78 | this.booksOverview.documentList, 79 | new Date(this.book.updated * 1000), 80 | this.userRepo 81 | ) 82 | fileGetters.push(epubExporter.init()) 83 | } 84 | 85 | if (this.bookRepo.export_unpacked_epub) { 86 | const unpackedEpubExporter = new UnpackedEpubBookGitlabExporter( 87 | this.booksOverview.schema, 88 | this.booksOverview.app.csl, 89 | this.booksOverview.styles, 90 | this.book, 91 | this.booksOverview.user, 92 | this.booksOverview.documentList, 93 | new Date(this.book.updated * 1000), 94 | this.userRepo 95 | ) 96 | fileGetters.push(unpackedEpubExporter.init()) 97 | } 98 | 99 | if (this.bookRepo.export_html) { 100 | const htmlExporter = new HTMLBookGitlabExporter( 101 | this.booksOverview.schema, 102 | this.booksOverview.app.csl, 103 | this.booksOverview.styles, 104 | this.book, 105 | this.booksOverview.user, 106 | this.booksOverview.documentList, 107 | new Date(this.book.updated * 1000), 108 | this.userRepo 109 | ) 110 | fileGetters.push(htmlExporter.init()) 111 | } 112 | 113 | if (this.bookRepo.export_unified_html) { 114 | const unifiedHtmlExporter = new SingleFileHTMLBookGitlabExporter( 115 | this.booksOverview.schema, 116 | this.booksOverview.app.csl, 117 | this.booksOverview.styles, 118 | this.book, 119 | this.booksOverview.user, 120 | this.booksOverview.documentList, 121 | new Date(this.book.updated * 1000), 122 | this.userRepo 123 | ) 124 | fileGetters.push(unifiedHtmlExporter.init()) 125 | } 126 | 127 | if (this.bookRepo.export_latex) { 128 | const latexExporter = new LatexBookGitlabExporter( 129 | this.booksOverview.schema, 130 | this.book, 131 | this.booksOverview.user, 132 | this.booksOverview.documentList, 133 | new Date(this.book.updated * 1000), 134 | this.userRepo 135 | ) 136 | fileGetters.push(latexExporter.init()) 137 | } 138 | if (this.bookRepo.export_docx) { 139 | const docxExporter = new DOCXBookGitlabExporter( 140 | this.booksOverview.schema, 141 | this.booksOverview.app.csl, 142 | this.book, 143 | this.booksOverview.user, 144 | this.booksOverview.documentList, 145 | new Date(this.book.updated * 1000), 146 | this.userRepo 147 | ) 148 | fileGetters.push(docxExporter.init()) 149 | } 150 | 151 | if (this.bookRepo.export_odt) { 152 | const odtExporter = new ODTBookGitlabExporter( 153 | this.booksOverview.schema, 154 | this.booksOverview.app.csl, 155 | this.book, 156 | this.booksOverview.user, 157 | this.booksOverview.documentList, 158 | new Date(this.book.updated * 1000), 159 | this.userRepo 160 | ) 161 | fileGetters.push(odtExporter.init()) 162 | } 163 | return Promise.all(fileGetters) 164 | .then(files => 165 | commitFiles( 166 | this.userRepo, 167 | commitMessage, 168 | Object.assign(...files) 169 | ) 170 | ) 171 | .then(returnCode => { 172 | switch (returnCode) { 173 | case 201: 174 | addAlert( 175 | "info", 176 | gettext( 177 | "Book published to repository successfully!" 178 | ) 179 | ) 180 | break 181 | case 304: 182 | addAlert( 183 | "info", 184 | gettext("Book already up to date in repository.") 185 | ) 186 | break 187 | case 400: 188 | addAlert( 189 | "error", 190 | gettext("Could not publish book to repository.") 191 | ) 192 | break 193 | } 194 | }) 195 | } 196 | } 197 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/static/js/modules/gitrepo_export/github/book_processor.js: -------------------------------------------------------------------------------- 1 | import {Dialog, addAlert, escapeText} from "../../common" 2 | import { 3 | DOCXBookGithubExporter, 4 | EpubBookGithubExporter, 5 | HTMLBookGithubExporter, 6 | LatexBookGithubExporter, 7 | ODTBookGithubExporter, 8 | SingleFileHTMLBookGithubExporter, 9 | UnpackedEpubBookGithubExporter 10 | } from "./book_exporters" 11 | import {commitTree, promiseChain} from "./tools" 12 | 13 | export class GithubBookProcessor { 14 | constructor(app, booksOverview, book, bookRepo, userRepo) { 15 | this.app = app 16 | this.booksOverview = booksOverview 17 | this.book = book 18 | this.bookRepo = bookRepo 19 | this.userRepo = userRepo 20 | } 21 | 22 | init() { 23 | return this.getCommitMessage() 24 | .then(commitMessage => this.publishBook(commitMessage)) 25 | .catch(() => {}) 26 | } 27 | 28 | getCommitMessage() { 29 | return new Promise((resolve, reject) => { 30 | const buttons = [ 31 | { 32 | text: gettext("Submit"), 33 | classes: "fw-dark", 34 | click: () => { 35 | const commitMessage = 36 | dialog.dialogEl.querySelector(".commit-message") 37 | .value || gettext("Update from Fidus Writer") 38 | dialog.close() 39 | resolve(commitMessage) 40 | } 41 | }, 42 | { 43 | type: "cancel", 44 | click: () => { 45 | dialog.close() 46 | reject() 47 | } 48 | } 49 | ] 50 | 51 | const dialog = new Dialog({ 52 | title: gettext("Commit message"), 53 | height: 150, 54 | body: `

55 | ${gettext("Updating")}: ${escapeText(this.book.title)} 56 | 59 |

`, 60 | buttons 61 | }) 62 | dialog.open() 63 | }) 64 | } 65 | 66 | publishBook(commitMessage) { 67 | addAlert("info", gettext("Book publishing to GitHub initiated.")) 68 | 69 | const commitInitiators = [] 70 | 71 | if (this.bookRepo.export_epub) { 72 | const epubExporter = new EpubBookGithubExporter( 73 | this.booksOverview.schema, 74 | this.booksOverview.app.csl, 75 | this.booksOverview.styles, 76 | this.book, 77 | this.booksOverview.user, 78 | this.booksOverview.documentList, 79 | new Date(this.book.updated * 1000), 80 | this.userRepo 81 | ) 82 | commitInitiators.push(epubExporter.init()) 83 | } 84 | 85 | if (this.bookRepo.export_unpacked_epub) { 86 | const unpackedEpubExporter = new UnpackedEpubBookGithubExporter( 87 | this.booksOverview.schema, 88 | this.booksOverview.app.csl, 89 | this.booksOverview.styles, 90 | this.book, 91 | this.booksOverview.user, 92 | this.booksOverview.documentList, 93 | new Date(this.book.updated * 1000), 94 | this.userRepo 95 | ) 96 | commitInitiators.push(unpackedEpubExporter.init()) 97 | } 98 | 99 | if (this.bookRepo.export_html) { 100 | const htmlExporter = new HTMLBookGithubExporter( 101 | this.booksOverview.schema, 102 | this.booksOverview.app.csl, 103 | this.booksOverview.styles, 104 | this.book, 105 | this.booksOverview.user, 106 | this.booksOverview.documentList, 107 | new Date(this.book.updated * 1000), 108 | this.userRepo 109 | ) 110 | commitInitiators.push(htmlExporter.init()) 111 | } 112 | 113 | if (this.bookRepo.export_unified_html) { 114 | const unifiedHtmlExporter = new SingleFileHTMLBookGithubExporter( 115 | this.booksOverview.schema, 116 | this.booksOverview.app.csl, 117 | this.booksOverview.styles, 118 | this.book, 119 | this.booksOverview.user, 120 | this.booksOverview.documentList, 121 | new Date(this.book.updated * 1000), 122 | this.userRepo 123 | ) 124 | commitInitiators.push(unifiedHtmlExporter.init()) 125 | } 126 | 127 | if (this.bookRepo.export_latex) { 128 | const latexExporter = new LatexBookGithubExporter( 129 | this.booksOverview.schema, 130 | this.book, 131 | this.booksOverview.user, 132 | this.booksOverview.documentList, 133 | new Date(this.book.updated * 1000), 134 | this.userRepo 135 | ) 136 | commitInitiators.push(latexExporter.init()) 137 | } 138 | 139 | if (this.bookRepo.export_docx) { 140 | const docxExporter = new DOCXBookGithubExporter( 141 | this.booksOverview.schema, 142 | this.booksOverview.app.csl, 143 | this.book, 144 | this.booksOverview.user, 145 | this.booksOverview.documentList, 146 | new Date(this.book.updated * 1000), 147 | this.userRepo 148 | ) 149 | commitInitiators.push(docxExporter.init()) 150 | } 151 | 152 | if (this.bookRepo.export_odt) { 153 | const odtExporter = new ODTBookGithubExporter( 154 | this.booksOverview.schema, 155 | this.booksOverview.app.csl, 156 | this.book, 157 | this.booksOverview.user, 158 | this.booksOverview.documentList, 159 | new Date(this.book.updated * 1000), 160 | this.userRepo 161 | ) 162 | commitInitiators.push(odtExporter.init()) 163 | } 164 | return Promise.all(commitInitiators).then(commitFunctions => 165 | promiseChain(commitFunctions.flat()).then(responses => { 166 | const responseCodes = responses.flat() 167 | if (responseCodes.every(code => code === 304)) { 168 | addAlert( 169 | "info", 170 | gettext("Book already up to date in repository.") 171 | ) 172 | } else if (responseCodes.every(code => code === 400)) { 173 | addAlert( 174 | "error", 175 | gettext("Could not publish book to repository.") 176 | ) 177 | } else if (responseCodes.find(code => code === 400)) { 178 | addAlert( 179 | "error", 180 | gettext( 181 | "Could not publish some parts of book to repository." 182 | ) 183 | ) 184 | } else { 185 | // The responses looks fine, but we are not done yet. 186 | commitTree( 187 | responseCodes.filter( 188 | response => typeof response === "object" 189 | ), 190 | commitMessage, 191 | this.userRepo 192 | ).then(() => 193 | addAlert( 194 | "info", 195 | gettext( 196 | "Book published to repository successfully!" 197 | ) 198 | ) 199 | ) 200 | } 201 | }) 202 | ) 203 | } 204 | } 205 | -------------------------------------------------------------------------------- /fiduswriter/gitrepo_export/static/js/modules/gitrepo_export/books_overview.js: -------------------------------------------------------------------------------- 1 | import {addAlert, findTarget, getJson, post} from "../common" 2 | import {GithubBookProcessor} from "./github" 3 | import {GitlabBookProcessor} from "./gitlab" 4 | import {repoSelectorTemplate} from "./templates" 5 | 6 | export class GitrepoExporterBooksOverview { 7 | constructor(booksOverview) { 8 | this.booksOverview = booksOverview 9 | this.userRepos = {} 10 | this.userReposMultitype = false 11 | this.bookRepos = {} 12 | this.finishedLoading = false 13 | this.openedBook = false 14 | } 15 | 16 | init() { 17 | const githubAccount = 18 | this.booksOverview.app.config.user.socialaccounts.find( 19 | account => account.provider === "github" 20 | ) 21 | const gitlabAccount = 22 | this.booksOverview.app.config.user.socialaccounts.find( 23 | account => account.provider === "gitlab" 24 | ) 25 | if (!githubAccount && !gitlabAccount) { 26 | return 27 | } 28 | Promise.all([this.getUserRepos(), this.getBookRepos()]).then(() => { 29 | this.finishedLoading = true 30 | const spinner = document.querySelector( 31 | "tbody.gitrepo-repository .fa-spinner" 32 | ) 33 | if (spinner) { 34 | document.querySelector("tbody.gitrepo-repository").innerHTML = 35 | repoSelectorTemplate({ 36 | book: this.openedBook, 37 | userRepos: this.userRepos, 38 | bookRepos: this.bookRepos, 39 | userReposMultitype: this.userReposMultitype 40 | }) 41 | } 42 | }) 43 | this.addButton() 44 | this.addDialogPart() 45 | this.addDialogSaveMethod() 46 | this.bind() 47 | } 48 | 49 | bind() { 50 | window.document.body.addEventListener("click", event => { 51 | const el = {} 52 | switch (true) { 53 | case findTarget(event, "tbody.gitrepo-repository .reload", el): 54 | this.resetUserRepos() 55 | break 56 | default: 57 | break 58 | } 59 | }) 60 | } 61 | 62 | resetUserRepos() { 63 | this.finishedLoading = false 64 | const repoSelector = document.querySelector("tbody.gitrepo-repository") 65 | if (repoSelector) { 66 | repoSelector.innerHTML = 67 | '' 68 | } 69 | 70 | this.getUserRepos(true).then(() => { 71 | this.finishedLoading = true 72 | const repoSelector = document.querySelector( 73 | "tbody.gitrepo-repository" 74 | ) 75 | if (repoSelector) { 76 | repoSelector.innerHTML = repoSelectorTemplate({ 77 | book: this.openedBook, 78 | userRepos: this.userRepos, 79 | bookRepos: this.bookRepos, 80 | userReposMultitype: this.userReposMultitype 81 | }) 82 | } 83 | }) 84 | } 85 | 86 | getUserRepos(reload = false) { 87 | if (reload) { 88 | this.userRepos = {} 89 | this.userReposMultitype = false 90 | } 91 | return getJson( 92 | `/api/gitrepo_export/get_git_repos/${reload ? "reload/" : ""}` 93 | ).then(({repos}) => { 94 | const initialType = repos.length ? repos[0].type : "" 95 | repos.forEach(entry => { 96 | this.userRepos[entry.type + "-" + entry.id] = entry 97 | if (entry.type !== initialType) { 98 | this.userReposMultitype = true 99 | } 100 | }) 101 | }) 102 | } 103 | 104 | getBookRepos() { 105 | return getJson("/api/gitrepo_export/get_book_repos/").then( 106 | ({repos}) => { 107 | this.bookRepos = repos 108 | } 109 | ) 110 | } 111 | 112 | getRepos(book) { 113 | const bookRepo = this.bookRepos[book.id] 114 | if (!bookRepo) { 115 | addAlert( 116 | "error", 117 | `${gettext( 118 | "There is no git repository registered for the book:" 119 | )} ${book.title}` 120 | ) 121 | return [false, false] 122 | } 123 | const userRepo = 124 | this.userRepos[bookRepo.repo_type + "-" + bookRepo.repo_id] 125 | if (!userRepo) { 126 | addAlert( 127 | "error", 128 | `${gettext("You do not have access to the repository:")} ${ 129 | bookRepo.github_repo_full_name 130 | }` 131 | ) 132 | return [bookRepo, false] 133 | } 134 | return [bookRepo, userRepo] 135 | } 136 | 137 | addButton() { 138 | this.booksOverview.dtBulkModel.content.push({ 139 | title: gettext("Export to Git Repository"), 140 | tooltip: gettext("Export selected to Git repository."), 141 | action: overview => { 142 | const ids = overview.getSelected() 143 | if (ids.length) { 144 | overview.bookList 145 | .filter(book => ids.includes(book.id)) 146 | .forEach(book => { 147 | const [bookRepo, userRepo] = this.getRepos(book) 148 | if (!userRepo) { 149 | return 150 | } 151 | const processor = 152 | userRepo.type === "github" 153 | ? new GithubBookProcessor( 154 | overview.app, 155 | overview, 156 | book, 157 | bookRepo, 158 | userRepo 159 | ) 160 | : new GitlabBookProcessor( 161 | overview.app, 162 | overview, 163 | book, 164 | bookRepo, 165 | userRepo 166 | ) 167 | processor.init() 168 | }) 169 | } 170 | }, 171 | disabled: overview => !overview.getSelected().length 172 | }) 173 | this.booksOverview.mod.actions.exportMenu.content.push({ 174 | title: gettext("Export to Git Repository"), 175 | tooltip: gettext("Export book to git repository."), 176 | action: ({saveBook, book, overview}) => { 177 | saveBook().then(() => { 178 | const [bookRepo, userRepo] = this.getRepos(book) 179 | if (!userRepo) { 180 | return 181 | } 182 | const processor = 183 | userRepo.type === "github" 184 | ? new GithubBookProcessor( 185 | overview.app, 186 | overview, 187 | book, 188 | bookRepo, 189 | userRepo 190 | ) 191 | : new GitlabBookProcessor( 192 | overview.app, 193 | overview, 194 | book, 195 | bookRepo, 196 | userRepo 197 | ) 198 | processor.init() 199 | }) 200 | } 201 | }) 202 | } 203 | 204 | addDialogPart() { 205 | this.booksOverview.mod.actions.dialogParts.push({ 206 | title: gettext("Git repository"), 207 | description: gettext("Git repository related settings"), 208 | template: ({book}) => { 209 | this.openedBook = book 210 | return ` 211 | 212 | ${ 213 | this.finishedLoading 214 | ? repoSelectorTemplate({ 215 | book, 216 | userRepos: this.userRepos, 217 | bookRepos: this.bookRepos, 218 | userReposMultitype: 219 | this.userReposMultitype 220 | }) 221 | : '' 222 | } 223 | 224 |
` 225 | } 226 | }) 227 | } 228 | 229 | addDialogSaveMethod() { 230 | this.booksOverview.mod.actions.onSave.push(book => { 231 | const repoSelector = document.querySelector( 232 | "#book-settings-repository" 233 | ) 234 | if (!repoSelector) { 235 | // Dialog may have been closed before the repoSelector was loaded 236 | return 237 | } 238 | const selected = repoSelector.value.split("-") 239 | const repoType = selected[0] 240 | let repoId = parseInt(selected[1]) 241 | const exportEpub = document.querySelector( 242 | "#book-settings-repository-epub" 243 | ).checked 244 | const exportUnpackedEpub = document.querySelector( 245 | "#book-settings-repository-unpacked-epub" 246 | ).checked 247 | const exportHtml = document.querySelector( 248 | "#book-settings-repository-html" 249 | ).checked 250 | const exportUnifiedHtml = document.querySelector( 251 | "#book-settings-repository-unified-html" 252 | ).checked 253 | const exportLatex = document.querySelector( 254 | "#book-settings-repository-latex" 255 | ).checked 256 | const exportDocx = document.querySelector( 257 | "#book-settings-repository-docx" 258 | ).checked 259 | const exportOdt = document.querySelector( 260 | "#book-settings-repository-odt" 261 | ).checked 262 | if ( 263 | !exportEpub && 264 | !exportUnpackedEpub && 265 | !exportHtml && 266 | !exportUnifiedHtml && 267 | !exportLatex && 268 | !exportDocx && 269 | !exportOdt 270 | ) { 271 | // No export formats selected. Reset repository. 272 | repoId = 0 273 | } 274 | if ( 275 | (repoId === 0 && this.bookRepos[book.id]) || 276 | (repoId > 0 && 277 | (!this.bookRepos[book.id] || 278 | this.bookRepos[book.id].repo_id !== repoId || 279 | this.bookRepos[book.id].export_epub !== exportEpub || 280 | this.bookRepos[book.id].export_unpacked_epub !== 281 | exportUnpackedEpub || 282 | this.bookRepos[book.id].export_html !== exportHtml || 283 | this.bookRepos[book.id].export_unified_html !== 284 | exportUnifiedHtml || 285 | this.bookRepos[book.id].export_latex !== exportLatex || 286 | this.bookRepos[book.id].export_odt !== exportOdt || 287 | this.bookRepos[book.id].export_docx !== exportDocx)) 288 | ) { 289 | const postData = { 290 | book_id: book.id, 291 | repo_type: repoType, 292 | repo_id: repoId 293 | } 294 | if (repoId > 0) { 295 | postData["repo_name"] = 296 | this.userRepos[`${repoType}-${repoId}`].name 297 | postData["export_epub"] = exportEpub 298 | postData["export_unpacked_epub"] = exportUnpackedEpub 299 | postData["export_html"] = exportHtml 300 | postData["export_unified_html"] = exportUnifiedHtml 301 | postData["export_latex"] = exportLatex 302 | postData["export_odt"] = exportOdt 303 | postData["export_docx"] = exportDocx 304 | } 305 | return post( 306 | "/api/gitrepo_export/update_book_repo/", 307 | postData 308 | ).then(() => { 309 | if (repoId === 0) { 310 | delete this.bookRepos[book.id] 311 | } else { 312 | this.bookRepos[book.id] = { 313 | repo_id: repoId, 314 | repo_type: repoType, 315 | repo_name: 316 | this.userRepos[`${repoType}-${repoId}`].name, 317 | export_epub: exportEpub, 318 | export_unpacked_epub: exportUnpackedEpub, 319 | export_html: exportHtml, 320 | export_unified_html: exportUnifiedHtml, 321 | export_latex: exportLatex, 322 | export_odt: exportOdt, 323 | export_docx: exportDocx 324 | } 325 | } 326 | }) 327 | } 328 | }) 329 | } 330 | } 331 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | --------------------------------------------------------------------------------