32 |
33 |
151 |
--------------------------------------------------------------------------------
/src/utils/onlyThisUtils.ts:
--------------------------------------------------------------------------------
1 | import { debugPush, logPush, warnPush } from "@/logger";
2 | import "@/utils/mathjax";
3 | import "mathjax/es5/tex-mml-svg";
4 | import { lang } from "./lang";
5 | import { showPluginMessage } from "./common";
6 |
7 | export function downloadSVG(svgElement) {
8 | let hiddenLink = document.createElement("a");
9 | let svgHTMLCode = serializeSVG(svgElement) //filterSVGouterHTML(svgElement.outerHTML);
10 | let blob = new Blob([svgHTMLCode], {
11 | type: "image/svg+xml",
12 | });
13 | hiddenLink.href = URL.createObjectURL(blob);
14 | hiddenLink.download = "export_SVG_" + new Date().toLocaleString() + ".svg";
15 | hiddenLink.click();
16 | }
17 |
18 | export function filterSVGouterHTML(str) {
19 | return str.replaceAll(" ", " ");
20 | }
21 |
22 | export function serializeSVG(svgElement) {
23 | let serializer = new XMLSerializer();
24 | let svgXml = serializer.serializeToString(svgElement);
25 | return svgXml;
26 | }
27 |
28 | export async function copySVG(svgElement) {
29 | throw Error("Not implemented");
30 | copyPlainTextToClipboard(svgElement.outerHTML);
31 | let svgHTMLCode = svgElement.outerHTML;
32 | const base64code = "data:image/svg+xml;base64," + utf8ToBase64(svgHTMLCode);
33 | logPush("writing to clipboard", base64code);
34 | const data = await fetch(base64code);
35 | const item = new ClipboardItem({ "image/svg+xml": data.blob()});
36 | navigator.clipboard.write([item]);
37 | showPluginMessage(lang("success:copy"));
38 | }
39 |
40 | function utf8ToBase64(str) {
41 | return window.btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) {
42 | return String.fromCharCode(parseInt(p1, 16));
43 | }));
44 | }
45 |
46 | export function handleSVGStringToSVGElement(dataUrl) {
47 | // 1. 提取编码后的 SVG 字符串(去掉前缀)
48 | const encodedSVG = dataUrl.split(',')[1];
49 |
50 | // 2. 解码成原始 SVG XML
51 | const svgText = decodeURIComponent(encodedSVG);
52 |
53 | // 3. 使用 DOMParser 解析为 SVGElement
54 | const parser = new DOMParser();
55 | const svgDoc = parser.parseFromString(svgText, "image/svg+xml");
56 | const svgElement = svgDoc.documentElement; // 这就是 SVGElement!
57 | return svgElement;
58 | }
59 |
60 | export async function copyImageBase64URLToClipboard(dataUrl) {
61 | checkClipboard();
62 | const res = await fetch(dataUrl);
63 | const blob = await res.blob();
64 |
65 | const item = new ClipboardItem({ [blob.type]: blob });
66 | await navigator.clipboard.write([item]);
67 | showPluginMessage(lang("success:copy"));
68 | }
69 |
70 | export async function downloadImageBase64URL(dataUrl:string) {
71 | const a = document.createElement("a");
72 | a.href = dataUrl;
73 | a.download = "downloaded_image_" + new Date().toLocaleString()+ ".png";
74 | document.body.appendChild(a);
75 | a.click();
76 | document.body.removeChild(a);
77 | }
78 |
79 | /**
80 | * SVG to canvas
81 | * @param svgElement
82 | * @param callback
83 | * @param remvoeBG
84 | *
85 | * Generate/Modify From: (Under Apache-2.0 license)
86 | * https://github.com/QianJianTech/LaTeXLive/blob/3703d8fa4e1df598b3384c7ef60af3c3d00385ea/js/latex/action.js#L172-L241
87 | */
88 | export function getCanvasFromSVG(svgElement, callback, removeBG=false) {
89 | // Clone the SVG element
90 | let svgClone = svgElement.cloneNode(true);
91 |
92 | // 获取 SVG 的原始尺寸
93 | let viewBox = svgElement.viewBox.baseVal;
94 | let origWidth = viewBox && viewBox.width ? viewBox.width : svgElement.clientWidth || 800;
95 | let origHeight = viewBox && viewBox.height ? viewBox.height : svgElement.clientHeight || 600;
96 | let aspectRatio = origWidth / origHeight;
97 |
98 | // 设置目标渲染尺寸(保持比例)
99 | let targetWidth = 1920;
100 | let targetHeight = Math.round(targetWidth / aspectRatio);
101 |
102 | svgClone.setAttribute("width", targetWidth + "px");
103 | svgClone.setAttribute("height", targetHeight + "px");
104 |
105 | // Convert the SVG to XML
106 | let svgXml = serializeSVG(svgClone);
107 | let image = new Image();
108 | image.src = "data:image/svg+xml;base64," + utf8ToBase64(svgXml);
109 |
110 | image.onerror = function (e) {
111 | console.error("SVG image failed to load", e);
112 | };
113 |
114 | image.onload = function () {
115 | // === 第一步:把 SVG 渲染到一个大画布上(保持比例)
116 | let scale = 2; // 提高分辨率因子(2 = 2倍分辨率,可调节)
117 | let canvas = document.createElement("canvas");
118 | canvas.width = targetWidth * scale;
119 | canvas.height = targetHeight * scale;
120 |
121 | let context = canvas.getContext("2d");
122 | context.drawImage(image, 0, 0, canvas.width, canvas.height);
123 | if (!removeBG) {
124 | callback(canvas, context);
125 | return;
126 | }
127 | // === 第二步:检测非透明区域(提交到工作线程)
128 | let imgData = context.getImageData(0, 0, canvas.width, canvas.height).data;
129 | const worker = new Worker(new URL('./imageProcessorWorker.js', import.meta.url));
130 | worker.onmessage = (event) => {
131 | const { lOffset, rOffset, tOffset, bOffset } = event.data;
132 | // === 第三步:裁剪并输出(保持比例)
133 | let cropWidth = rOffset - lOffset;
134 | let cropHeight = bOffset - tOffset;
135 |
136 | let canvas2 = document.createElement("canvas");
137 | canvas2.width = cropWidth;
138 | canvas2.height = cropHeight;
139 | let context2 = canvas2.getContext("2d");
140 |
141 | // 裁剪部分原样绘制(不再强行拉伸)
142 | context2.drawImage(
143 | canvas,
144 | lOffset,
145 | tOffset,
146 | cropWidth,
147 | cropHeight,
148 | 0,
149 | 0,
150 | cropWidth,
151 | cropHeight
152 | );
153 |
154 | callback(canvas2, context2);
155 | };
156 | worker.postMessage({ imgData, width: canvas.width, height: canvas.height });
157 | };
158 | }
159 |
160 | export function downloadImageFromCanvas(canvas) {
161 | // Create a hidden link to download the resulting image
162 | let hiddenLink = document.createElement("a");
163 | hiddenLink.href = canvas.toDataURL("image/png");
164 | hiddenLink.download = "downloaded_image_" + new Date().toLocaleString()+ ".png";
165 | hiddenLink.click();
166 | }
167 |
168 | export function copyImageToClipboard(canvas) {
169 | checkClipboard();
170 | canvas.toBlob(function (blob) {
171 | logPush("writing to clipboard");
172 | const item = new ClipboardItem({ "image/png": blob });
173 | navigator.clipboard.write([item]);
174 | showPluginMessage(lang("success:copy"));
175 | });
176 | }
177 |
178 | export function copyPlainTextToClipboard(text) {
179 | checkClipboard();
180 | const item = new ClipboardItem({ "text/plain": new Blob([text], { type: 'text/plain' }) });
181 | navigator.clipboard.write([item]);
182 | showPluginMessage(lang("success:copy"));
183 | }
184 |
185 | export function checkClipboard(sendMessage = true) {
186 | if (!navigator.clipboard) {
187 | if (sendMessage) {
188 | showPluginMessage(lang("error:clipboard"));
189 | }
190 | return false;
191 | }
192 | return true;
193 | }
194 |
195 | export function convertToMathML(katexString) {
196 | try {
197 | // 使用 KaTeX 将 LaTeX 字符串转换为 MathML
198 | const katexOutput = window.katex.renderToString(katexString, {
199 | output: 'mathml',
200 | });
201 |
202 | // 移除最外层的 标签
203 | const div = document.createElement('div');
204 | div.innerHTML = katexOutput;
205 | const mathML = div.querySelector('math').outerHTML;
206 |
207 | return mathML;
208 | } catch (error) {
209 | console.error('Error converting to MathML:', error);
210 | return '';
211 | }
212 | }
213 |
214 |
215 | export async function mathmlToSvg(mathmlString) {
216 | return new Promise((resolve, reject) => {
217 | // Ensure MathJax is loaded and configured
218 | if (typeof MathJax === 'undefined') {
219 | reject(new Error('MathJax is not loaded'));
220 | return;
221 | }
222 |
223 | const div = document.createElement('div');
224 | div.setAttribute("id", "temp");
225 | div.style.opacity = "0.0";
226 | div.style.display = "overflow";
227 | div.style.zIndex = "-999";
228 | document.body.appendChild(div);
229 | div.innerHTML = mathmlString;
230 | MathJax.typesetPromise([div]).then(() => {
231 | const svg = div.querySelector('svg');
232 | if (svg) {
233 | div.remove();
234 | resolve(svg);
235 | } else {
236 | div.remove();
237 | reject(new Error('SVG element not found'));
238 | }
239 | }).catch((err) => {
240 | reject(new Error('Error rendering MathML: ' + err.message));
241 | });
242 | });
243 | }
--------------------------------------------------------------------------------
/src/utils/common.ts:
--------------------------------------------------------------------------------
1 | import { getBackend, IProtyle, openMobileFileById, openTab, showMessage } from "siyuan";
2 | import { isEventCtrlKey, isValidStr } from "./commonCheck";
3 | import { debugPush, logPush, warnPush } from "@/logger";
4 | import { getPluginInstance } from "./pluginHelper";
5 | import { getCurrentDocIdF, isMobile } from "@/syapi";
6 | import { removeCurrentTabF } from "@/syapi/custom";
7 | import { lang } from "./lang";
8 |
9 | export function getToken(): string {
10 | return "";
11 | }
12 |
13 | export function showPluginMessage(message: string, timeout?: number, type?: "info" | "error"): void {
14 | const pluginName = lang("name");
15 | const prefixedMessage = `${message} —— ${pluginName}`;
16 | showMessage(prefixedMessage, timeout, type);
17 | }
18 |
19 | /**
20 | * 在protyle所在的分屏中打开
21 | * @param event
22 | * @param protyleElem
23 | * @deprecated
24 | */
25 | export function openRefLinkInProtyleWnd(protyleElem: IProtyle, openInFocus: boolean, event: MouseEvent) {
26 | logPush("debug", event, protyleElem);
27 | openRefLink(event, null, null, protyleElem, openInFocus);
28 | }
29 |
30 | /**
31 | * 休息一下,等待
32 | * @param time 单位毫秒
33 | * @returns
34 | */
35 | export function sleep(time:number){
36 | return new Promise((resolve) => setTimeout(resolve, time));
37 | }
38 |
39 | export function getFocusedBlockId() {
40 | const focusedBlock = getFocusedBlock();
41 | if (focusedBlock == null) {
42 | return null;
43 | }
44 | return focusedBlock.dataset.nodeId;
45 | }
46 |
47 |
48 | export function getFocusedBlock() {
49 | if (document.activeElement.classList.contains('protyle-wysiwyg')) {
50 | /* 光标在编辑区内 */
51 | let block = window.getSelection()?.focusNode?.parentElement; // 当前光标
52 | while (block != null && block?.dataset?.nodeId == null) block = block.parentElement;
53 | return block;
54 | }
55 | else return null;
56 | }
57 |
58 | /**
59 | * 在点击时打开思源块/文档
60 | * 为引入本项目,和原代码相比有更改
61 | * @refer https://github.com/leolee9086/cc-template/blob/6909dac169e720d3354d77685d6cc705b1ae95be/baselib/src/commonFunctionsForSiyuan.js#L118-L141
62 | * @license 木兰宽松许可证
63 | * @param {MouseEvent} event 当给出event时,将寻找event.currentTarget的data-node-id作为打开的文档id
64 | * @param {string} docId,此项仅在event对应的发起Elem上找不到data node id的情况下使用
65 | * @param {any} keyParam event的Key,主要是ctrlKey shiftKey等,此项仅在event无效时使用
66 | * @param {IProtyle} protyleElem 如果不为空打开文档点击事件将在该Elem上发起
67 | * @param {boolean} openInFocus 在当前聚焦的窗口中打开,给定此项为true,则优于protyle选项生效
68 | * @deprecated 请使用openRefLinkByAPI
69 | */
70 | export function openRefLink(event: MouseEvent, paramId = "", keyParam = undefined, protyleElem = undefined, openInFocus = false){
71 | let syMainWndDocument= window.parent.document
72 | let id;
73 | if (event && (event.currentTarget as HTMLElement)?.getAttribute("data-node-id")) {
74 | id = (event.currentTarget as HTMLElement)?.getAttribute("data-node-id");
75 | } else if ((event?.currentTarget as HTMLElement)?.getAttribute("data-id")) {
76 | id = (event.currentTarget as HTMLElement)?.getAttribute("data-id");
77 | } else {
78 | id = paramId;
79 | }
80 | // 处理笔记本等无法跳转的情况
81 | if (!isValidStr(id)) {
82 | debugPush("错误的id", id)
83 | return;
84 | }
85 | event?.preventDefault();
86 | event?.stopPropagation();
87 | debugPush("openRefLinkEvent", event);
88 | let simulateLink = syMainWndDocument.createElement("span")
89 | simulateLink.setAttribute("data-type","a")
90 | simulateLink.setAttribute("data-href", "siyuan://blocks/" + id)
91 | simulateLink.style.display = "none";//不显示虚拟链接,防止视觉干扰
92 | let tempTarget = null;
93 | // 如果提供了目标protyle,在其中插入
94 | if (protyleElem && !openInFocus) {
95 | tempTarget = protyleElem.querySelector(".protyle-wysiwyg div[data-node-id] div[contenteditable]") ?? protyleElem;
96 | debugPush("openRefLink使用提供窗口", tempTarget);
97 | }
98 | debugPush("openInFocus?", openInFocus);
99 | if (openInFocus) {
100 | // 先确定Tab
101 | const dataId = syMainWndDocument.querySelector(".layout__wnd--active .layout-tab-bar .item--focus")?.getAttribute("data-id");
102 | debugPush("openRefLink尝试使用聚焦窗口", dataId);
103 | // 再确定Protyle
104 | if (isValidStr(dataId)) {
105 | tempTarget = window.document.querySelector(`.fn__flex-1.protyle[data-id='${dataId}']
106 | .protyle-wysiwyg div[data-node-id] div[contenteditable]`);
107 | debugPush("openRefLink使用聚焦窗口", tempTarget);
108 | }
109 | }
110 | if (!isValidStr(tempTarget)) {
111 | tempTarget = syMainWndDocument.querySelector(".protyle-wysiwyg div[data-node-id] div[contenteditable]");
112 | debugPush("openRefLink未能找到指定窗口,更改为原状态");
113 | }
114 | tempTarget.appendChild(simulateLink);
115 | let clickEvent = new MouseEvent("click", {
116 | ctrlKey: event?.ctrlKey ?? keyParam?.ctrlKey,
117 | shiftKey: event?.shiftKey ?? keyParam?.shiftKey,
118 | altKey: event?.altKey ?? keyParam?.altKey,
119 | metaKey: event?.metaKey ?? keyParam?.metaKey,
120 | bubbles: true
121 | });
122 | // 存在选区时,ref相关点击是不执行的,这里暂存、清除,并稍后恢复
123 | const tempSaveRanges = [];
124 | const selection = window.getSelection();
125 | for (let i = 0; i < selection.rangeCount; i++) {
126 | tempSaveRanges.push(selection.getRangeAt(i));
127 | }
128 | window.getSelection()?.removeAllRanges();
129 |
130 | simulateLink.dispatchEvent(clickEvent);
131 | simulateLink.remove();
132 |
133 | // // 恢复选区,不确定恢复选区是否会导致其他问题
134 | // if (selection.isCollapsed) {
135 | // tempSaveRanges.forEach(range => selection.addRange(range)); // 恢复选区
136 | // }
137 | }
138 |
139 | let lastClickTime_openRefLinkByAPI = 0;
140 | /**
141 | * 基于API的打开思源块/文档
142 | * @param mouseEvent 鼠标点击事件,如果存在,优先使用
143 | * @param paramDocId 如果没有指定 event,使用此参数作为文档id
144 | * @param keyParam 如果没有event,使用此次数指定ctrlKey后台打开、shiftKey下方打开、altKey右侧打开
145 | * @param openInFocus 是否以聚焦块的方式打开(此参数有变动)
146 | * @param removeCurrentTab 是否移除当前Tab
147 | * @param autoRemoveJudgeMiliseconds 自动判断是否移除当前Tab的时间间隔(0则 不自动判断)
148 | * @returns
149 | */
150 | export function openRefLinkByAPI({mouseEvent, paramDocId = "", keyParam = {}, openInFocus = undefined, removeCurrentTab = undefined, autoRemoveJudgeMiliseconds = 0}: {mouseEvent?: MouseEvent, paramDocId?: string, keyParam?: any, openInFocus?: boolean, removeCurrentTab?: boolean, autoRemoveJudgeMiliseconds?: number}) {
151 | let docId: string;
152 | if (mouseEvent && (mouseEvent.currentTarget as HTMLElement)?.getAttribute("data-node-id")) {
153 | docId = (mouseEvent.currentTarget as HTMLElement)?.getAttribute("data-node-id");
154 | } else if ((mouseEvent?.currentTarget as HTMLElement)?.getAttribute("data-id")) {
155 | docId = (mouseEvent.currentTarget as HTMLElement)?.getAttribute("data-id");
156 | } else {
157 | docId = paramDocId;
158 | }
159 | // 处理笔记本等无法跳转的情况
160 | if (!isValidStr(docId)) {
161 | debugPush("错误的id", docId)
162 | return;
163 | }
164 | // 需要冒泡,否则不能在所在页签打开
165 | // event?.preventDefault();
166 | // event?.stopPropagation();
167 | if (isMobile()) {
168 | openMobileFileById(getPluginInstance().app, docId);
169 | return;
170 | }
171 | debugPush("openRefLinkEventAPIF", mouseEvent);
172 | if (mouseEvent) {
173 | keyParam = {};
174 | keyParam["ctrlKey"] = mouseEvent.ctrlKey;
175 | keyParam["shiftKey"] = mouseEvent.shiftKey;
176 | keyParam["altKey"] = mouseEvent.altKey;
177 | keyParam["metaKey"] = mouseEvent.metaKey;
178 | }
179 | let positionKey = undefined;
180 | if (keyParam["altKey"]) {
181 | positionKey = "right";
182 | } else if (keyParam["shiftKey"]) {
183 | positionKey = "bottom";
184 | }
185 | if (autoRemoveJudgeMiliseconds > 0) {
186 | if (Date.now() - lastClickTime_openRefLinkByAPI < autoRemoveJudgeMiliseconds) {
187 | removeCurrentTab = true;
188 | }
189 | lastClickTime_openRefLinkByAPI = Date.now();
190 | }
191 | // 手动关闭
192 | const needToCloseDocId = getCurrentDocIdF(true);
193 |
194 | const finalParam = {
195 | app: getPluginInstance().app,
196 | doc: {
197 | id: docId,
198 | zoomIn: openInFocus
199 | },
200 | position: positionKey,
201 | keepCursor: isEventCtrlKey(keyParam) ? true : undefined,
202 | removeCurrentTab: removeCurrentTab, // 目前这个选项的行为是:true,则当前页签打开;false,则根据思源设置:新页签打开
203 | };
204 | debugPush("打开文档执行参数", finalParam);
205 | openTab(finalParam);
206 | // 后台打开页签不可移除
207 | if (removeCurrentTab && !isEventCtrlKey(keyParam)) {
208 | debugPush("插件自行移除页签");
209 | removeCurrentTabF(needToCloseDocId);
210 | removeCurrentTab = false;
211 | }
212 | }
213 |
214 |
215 |
216 | export function parseDateString(dateString: string): Date | null {
217 | if (dateString.length !== 14) {
218 | warnPush("Invalid date string length. Expected format: 'YYYYMMDDHHmmss'");
219 | return null;
220 | }
221 |
222 | const year = parseInt(dateString.slice(0, 4), 10);
223 | const month = parseInt(dateString.slice(4, 6), 10) - 1; // 月份从 0 开始
224 | const day = parseInt(dateString.slice(6, 8), 10);
225 | const hours = parseInt(dateString.slice(8, 10), 10);
226 | const minutes = parseInt(dateString.slice(10, 12), 10);
227 | const seconds = parseInt(dateString.slice(12, 14), 10);
228 |
229 | const date = new Date(year, month, day, hours, minutes, seconds);
230 |
231 | if (isNaN(date.getTime())) {
232 | warnPush("Invalid date components.");
233 | return null;
234 | }
235 |
236 | return date;
237 | }
238 |
239 | export function generateUUID() {
240 | let uuid = '';
241 | let i = 0;
242 | let random = 0;
243 |
244 | for (i = 0; i < 36; i++) {
245 | if (i === 8 || i === 13 || i === 18 || i === 23) {
246 | uuid += '-';
247 | } else if (i === 14) {
248 | uuid += '4';
249 | } else {
250 | random = Math.random() * 16 | 0;
251 | if (i === 19) {
252 | random = (random & 0x3) | 0x8;
253 | }
254 | uuid += (random).toString(16);
255 | }
256 | }
257 |
258 | return uuid;
259 | }
260 |
261 | export function isPluginExist(pluginName: string) {
262 | const plugins = window.siyuan.ws.app.plugins;
263 | return plugins?.some((plugin) => plugin.name === pluginName);
264 | }
265 |
266 | export function isAnyPluginExist(pluginNames: string[]) {
267 | return pluginNames.some(isPluginExist);
268 | }
269 |
270 | export function replaceShortcutString(shortcut:string) {
271 | const backend = getBackend();
272 |
273 | if (backend !== "darwin") {
274 | return shortcut
275 | .replace(/⌥/g, 'Alt ') // 替换 Option 键
276 | .replace(/⌘/g, 'Ctrl ') // 替换 Command 键
277 | .replace(/⇧/g, 'Shift ') // 替换 Shift 键
278 | .replace(/⇪/g, 'CapsLock ') // 替换 Caps Lock 键
279 | .replace(/⌃/g, 'Ctrl '); // 替换 Control 键
280 | }
281 |
282 | return shortcut;
283 | }
284 |
--------------------------------------------------------------------------------
/src/syapi/index.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * API.js
3 | * 用于发送思源api请求。
4 | */
5 | import { getToken } from "@/utils/common";
6 | import { isValidStr } from "@/utils/commonCheck";
7 | import { logPush, warnPush, errorPush, debugPush } from "@/logger"
8 | /**向思源api发送请求
9 | * @param data 传递的信息(body)
10 | * @param url 请求的地址
11 | */
12 | export async function postRequest(data: any, url:string){
13 | let result;
14 | await fetch(url, {
15 | body: JSON.stringify(data),
16 | method: 'POST',
17 | headers: {
18 | // "Authorization": "Token "+ getToken(),
19 | "Content-Type": "application/json"
20 | }
21 | }).then((response) => {
22 | result = response.json();
23 | });
24 | return result;
25 | }
26 |
27 | export async function getResponseData(promiseResponse){
28 | const response = await promiseResponse;
29 | if (response.code != 0 || response.data == null){
30 | return null;
31 | }else{
32 | return response.data;
33 | }
34 | }
35 |
36 | /**
37 | * 检查请求是否成功,返回0、-1
38 | * @param {*} response
39 | * @returns 成功为0,失败为-1
40 | */
41 | export async function checkResponse(response){
42 | if (response.code == 0){
43 | return 0;
44 | }else{
45 | return -1;
46 | }
47 | }
48 |
49 | /**SQL(api)
50 | * @param sqlstmt SQL语句
51 | */
52 | export async function queryAPI(sqlstmt:string){
53 | let url = "/api/query/sql";
54 | let response = await postRequest({stmt: sqlstmt},url);
55 | if (response.code == 0 && response.data != null){
56 | return response.data;
57 | }
58 | if (response.msg != "") {
59 | throw new Error(`SQL ERROR: ${response.msg}`);
60 | }
61 |
62 | return [];
63 | }
64 |
65 | /**重建索引
66 | * @param docpath 需要重建索引的文档路径
67 | */
68 | export async function reindexDoc(docpath){
69 | let url = "/api/filetree/reindexTree";
70 | await postRequest({path: docpath},url);
71 | return 0;
72 | }
73 |
74 | /**列出子文件(api)
75 | * @param notebookId 笔记本id
76 | * @param path 需要列出子文件的路径
77 | * @param maxListCount 子文档最大显示数量
78 | * @param sort 排序方式(类型号)
79 | */
80 | export async function listDocsByPathT({notebook, path, maxListCount = undefined, sort = undefined, ignore = true, showHidden = null}){
81 | let url = "/api/filetree/listDocsByPath";
82 | let body = {
83 | "notebook": notebook,
84 | "path": path
85 | }
86 | if (maxListCount != undefined && maxListCount >= 0) {
87 | body["maxListCount"] = maxListCount;
88 | }
89 | if (sort != undefined && sort != DOC_SORT_TYPES.FOLLOW_DOC_TREE && sort != DOC_SORT_TYPES.UNASSIGNED) {
90 | body["sort"] = sort;
91 | }
92 | if (ignore != undefined) {
93 | body["ignoreMaxListHint"] = ignore;
94 | }
95 | if (showHidden != null) {
96 | body["showHidden"] = showHidden;
97 | }
98 | let response = await postRequest(body, url);
99 | if (response.code != 0 || response.data == null){
100 | warnPush("listDocsByPath请求错误", response.msg);
101 | return new Array();
102 | }
103 | return response.data.files;
104 | }
105 |
106 | /**
107 | * 添加属性(API)
108 | * @param attrs 属性对象
109 | * @param 挂件id
110 | * */
111 | export async function addblockAttrAPI(attrs, blockid){
112 | let url = "/api/attr/setBlockAttrs";
113 | let attr = {
114 | id: blockid,
115 | attrs: attrs
116 | }
117 | let result = await postRequest(attr, url);
118 | return checkResponse(result);
119 | }
120 |
121 | /**获取挂件块参数(API)
122 | * @param blockid
123 | * @return response 请访问result.data获取对应的属性
124 | */
125 | export async function getblockAttr(blockid){
126 | let url = "/api/attr/getBlockAttrs";
127 | let response = await postRequest({id: blockid}, url);
128 | if (response.code != 0){
129 | throw Error("获取挂件块参数失败");
130 | }
131 | return response.data;
132 | }
133 |
134 | /**
135 | * 更新块(返回值有删减)
136 | * @param {String} text 更新写入的文本
137 | * @param {String} blockid 更新的块id
138 | * @param {String} textType 文本类型,markdown、dom可选
139 | * @returns 对象,为response.data[0].doOperations[0]的值,返回码为-1时也返回null
140 | */
141 | export async function updateBlockAPI(text, blockid, textType = "markdown"){
142 | let url = "/api/block/updateBlock";
143 | let data = {dataType: textType, data: text, id: blockid};
144 | let response = await postRequest(data, url);
145 | try{
146 | if (response.code == 0 && response.data != null && isValidStr(response.data[0].doOperations[0].id)){
147 | return response.data[0].doOperations[0];
148 | }
149 | if (response.code == -1){
150 | warnPush("更新块失败", response.msg);
151 | return null;
152 | }
153 | }catch(err){
154 | errorPush(err);
155 | warnPush(response.msg);
156 | }
157 | return null;
158 | }
159 |
160 | /**
161 | * 插入块(返回值有删减)
162 | * @param {string} text 文本
163 | * @param {string} blockid 指定的块
164 | * @param {string} textType 插入的文本类型,"markdown" or "dom"
165 | * @param {string} addType 插入到哪里?默认插入为指定块之后,NEXT 为插入到指定块之前, PARENT 为插入为指定块的子块
166 | * @return 对象,为response.data[0].doOperations[0]的值,返回码为-1时也返回null
167 | */
168 | export async function insertBlockAPI(text, blockid, addType = "previousID", textType = "markdown", ){
169 | let url = "/api/block/insertBlock";
170 | let data = {dataType: textType, data: text};
171 | switch (addType) {
172 | case "parentID":
173 | case "PARENT":
174 | case "parentId": {
175 | data["parentID"] = blockid;
176 | break;
177 | }
178 | case "nextID":
179 | case "NEXT":
180 | case "nextId": {
181 | data["nextID"] = blockid;
182 | break;
183 | }
184 | case "previousID":
185 | case "PREVIOUS":
186 | case "previousId":
187 | default: {
188 | data["previousID"] = blockid;
189 | break;
190 | }
191 | }
192 | let response = await postRequest(data, url);
193 | try{
194 | if (response.code == 0 && response.data != null && isValidStr(response.data[0].doOperations[0].id)){
195 | return response.data[0].doOperations[0];
196 | }
197 | if (response.code == -1){
198 | warnPush("插入块失败", response.msg);
199 | return null;
200 | }
201 | }catch(err){
202 | errorPush(err);
203 | warnPush(response.msg);
204 | }
205 | return null;
206 |
207 | }
208 |
209 | /**
210 | * 获取文档大纲
211 | * @param {string} docid 要获取的文档id
212 | * @returns {*} 响应的data部分,为outline对象数组
213 | */
214 | export async function getDocOutlineAPI(docid){
215 | let url = "/api/outline/getDocOutline";
216 | let data = {"id": docid};
217 | let response = await postRequest(data, url);
218 | if (response.code == 0){
219 | return response.data;
220 | }else{
221 | return null;
222 | }
223 | }
224 |
225 | /**
226 | * 插入为后置子块
227 | * @param {*} text 子块文本
228 | * @param {*} parentId 父块id
229 | * @param {*} textType 默认为"markdown"
230 | * @returns
231 | */
232 | export async function prependBlockAPI(text, parentId, textType = "markdown"){
233 | let url = "/api/block/prependBlock";
234 | let data = {"dataType": textType, "data": text, "parentID": parentId};
235 | let response = await postRequest(data, url);
236 | try{
237 | if (response.code == 0 && response.data != null && isValidStr(response.data[0].doOperations[0].id)){
238 | return response.data[0].doOperations[0];
239 | }
240 | if (response.code == -1){
241 | warnPush("插入块失败", response.msg);
242 | return null;
243 | }
244 | }catch(err){
245 | errorPush(err);
246 | warnPush(response.msg);
247 | }
248 | return null;
249 |
250 | }
251 | /**
252 | * 插入为前置子块
253 | * @param {*} text 子块文本
254 | * @param {*} parentId 父块id
255 | * @param {*} textType 默认为markdown
256 | * @returns
257 | */
258 | export async function appendBlockAPI(text, parentId, textType = "markdown"){
259 | let url = "/api/block/appendBlock";
260 | let data = {"dataType": textType, "data": text, "parentID": parentId};
261 | let response = await postRequest(data, url);
262 | try{
263 | if (response.code == 0 && response.data != null && isValidStr(response.data[0].doOperations[0].id)){
264 | return response.data[0].doOperations[0];
265 | }
266 | if (response.code == -1){
267 | warnPush("插入块失败", response.msg);
268 | return null;
269 | }
270 | }catch(err){
271 | errorPush(err);
272 | warnPush(response.msg);
273 | }
274 | return null;
275 |
276 | }
277 |
278 | /**
279 | * 推送普通消息
280 | * @param {string} msgText 推送的内容
281 | * @param {number} timeout 显示时间,单位毫秒
282 | * @return 0正常推送 -1 推送失败
283 | */
284 | export async function pushMsgAPI(msgText, timeout){
285 | let url = "/api/notification/pushMsg";
286 | let response = await postRequest({msg: msgText, timeout: timeout}, url);
287 | if (response.code != 0 || response.data == null || !isValidStr(response.data.id)){
288 | return -1;
289 | }
290 | return 0;
291 | }
292 |
293 | /**
294 | * 获取当前文档id(伪api)
295 | * 优先使用jquery查询
296 | * @param {boolean} mustSure 是否必须确认,若为true,找到多个打开中的文档时返回null
297 | */
298 | export function getCurrentDocIdF(mustSure: boolean = false) {
299 | let thisDocId:string = null;
300 | // 桌面端
301 | thisDocId = window.top.document.querySelector(".layout__wnd--active .protyle.fn__flex-1:not(.fn__none) .protyle-background")?.getAttribute("data-node-id");
302 | debugPush("尝试获取当前具有焦点的id", thisDocId);
303 | let temp:string = null;
304 | // 移动端
305 | if (!thisDocId && isMobile()) {
306 | // UNSTABLE: 面包屑样式变动将导致此方案错误!
307 | try {
308 | temp = window.top.document.querySelector(".protyle-breadcrumb .protyle-breadcrumb__item .popover__block[data-id]")?.getAttribute("data-id");
309 | let iconArray = window.top.document.querySelectorAll(".protyle-breadcrumb .protyle-breadcrumb__item .popover__block[data-id]");
310 | for (let i = 0; i < iconArray.length; i++) {
311 | let iconOne = iconArray[i];
312 | if (iconOne.children.length > 0
313 | && iconOne.children[0].getAttribute("xlink:href") == "#iconFile"){
314 | temp = iconOne.getAttribute("data-id");
315 | break;
316 | }
317 | }
318 | thisDocId = temp;
319 | }catch(e){
320 | console.error(e);
321 | temp = null;
322 | }
323 | }
324 | // 无聚焦窗口
325 | if (!thisDocId) {
326 | thisDocId = window.top.document.querySelector(".protyle.fn__flex-1:not(.fn__none) .protyle-background")?.getAttribute("data-node-id");
327 | debugPush("获取具有焦点id失败,获取首个打开中的文档", thisDocId);
328 | if (mustSure && window.top.document.querySelectorAll(".protyle.fn__flex-1:not(.fn__none) .protyle-background").length > 1) {
329 | debugPush("要求必须唯一确认,但是找到多个打开中的文档");
330 | return null;
331 | }
332 | }
333 | return thisDocId;
334 | }
335 |
336 | export function getAllShowingDocId(): string[] {
337 | if (isMobile()) {
338 | return [getCurrentDocIdF()];
339 | } else {
340 | const elemList = window.document.querySelectorAll("[data-type=wnd] .protyle.fn__flex-1:not(.fn__none) .protyle-background");
341 | const result = [].map.call(elemList, function(elem: Element) {
342 | return elem.getAttribute("data-node-id");
343 | });
344 | return result
345 | }
346 | }
347 |
348 | /**
349 | * 获取当前挂件id
350 | * @returns
351 | */
352 | export function getCurrentWidgetId(){
353 | try{
354 | if (!window.frameElement.parentElement.parentElement.dataset.nodeId) {
355 | return window.frameElement.parentElement.parentElement.dataset.id;
356 | }else{
357 | return window.frameElement.parentElement.parentElement.dataset.nodeId;
358 | }
359 | }catch(err){
360 | warnPush("getCurrentWidgetId window...nodeId方法失效");
361 | return null;
362 | }
363 | }
364 |
365 | /**
366 | * 检查运行的操作系统
367 | * @return true 可以运行,当前os在允许列表中
368 | */
369 | // export function checkOs(){
370 | // try{
371 | // if (setting.includeOs.indexOf(window.top.siyuan.config.system.os.toLowerCase()) != -1){
372 | // return true;
373 | // }
374 | // }catch(err){
375 | // errorPush(err);
376 | // warnPush("检查操作系统失败");
377 | // }
378 |
379 | // return false;
380 | // }
381 | /**
382 | * 删除块
383 | * @param {*} blockid
384 | * @returns
385 | */
386 | export async function removeBlockAPI(blockid){
387 | let url = "/api/block/deleteBlock";
388 | let response = await postRequest({id: blockid}, url);
389 | if (response.code == 0){
390 | return true;
391 | }
392 | warnPush("删除块失败", response);
393 | return false;
394 | }
395 |
396 | /**
397 | * 获取块kramdown源码
398 | * @param {*} blockid
399 | * @returns kramdown文本
400 | */
401 | export async function getKramdown(blockid){
402 | let url = "/api/block/getBlockKramdown";
403 | let response = await postRequest({id: blockid}, url);
404 | if (response.code == 0 && response.data != null && "kramdown" in response.data){
405 | return response.data.kramdown;
406 | }
407 | return null;
408 | }
409 |
410 | /**
411 | * 获取笔记本列表
412 | * @returns
413 | "id": "20210817205410-2kvfpfn",
414 | "name": "测试笔记本",
415 | "icon": "1f41b",
416 | "sort": 0,
417 | "closed": false
418 |
419 | */
420 | export async function getNodebookList() {
421 | let url = "/api/notebook/lsNotebooks";
422 | let response = await postRequest({}, url);
423 | if (response.code == 0 && response.data != null && "notebooks" in response.data){
424 | return response.data.notebooks;
425 | }
426 | return null;
427 | }
428 |
429 | /**
430 | * 基于本地window.siyuan获得笔记本信息
431 | * @param {*} notebookId 为空获得所有笔记本信息
432 | * @returns
433 | */
434 | export function getNotebookInfoLocallyF(notebookId = undefined) {
435 | try {
436 | if (!notebookId) return window.top.siyuan.notebooks;
437 | for (let notebookInfo of window.top.siyuan.notebooks) {
438 | if (notebookInfo.id == notebookId) {
439 | return notebookInfo;
440 | }
441 | }
442 | return undefined;
443 | }catch(err) {
444 | errorPush(err);
445 | return undefined;
446 | }
447 | }
448 |
449 | /**
450 | * 获取笔记本排序规则
451 | * (为“跟随文档树“的,转为文档树排序
452 | * @param {*} notebookId 笔记本id,不传则为文档树排序
453 | * @returns
454 | */
455 | export function getNotebookSortModeF(notebookId = undefined) {
456 | try {
457 | let fileTreeSort = window.top.siyuan.config.fileTree.sort;
458 | if (!notebookId) return fileTreeSort;
459 | let notebookSortMode = window.document.querySelector(`.file-tree.sy__file ul[data-url='${notebookId}']`)?.getAttribute("data-sortmode") ?? getNotebookInfoLocallyF(notebookId).sortMode;
460 | if (typeof notebookSortMode === "string") {
461 | notebookSortMode = parseInt(notebookSortMode, 10);
462 | }
463 | if (notebookSortMode == DOC_SORT_TYPES.UNASSIGNED || notebookSortMode == DOC_SORT_TYPES.FOLLOW_DOC_TREE) {
464 | return fileTreeSort;
465 | }
466 | return notebookSortMode;
467 | }catch(err) {
468 | errorPush(err);
469 | return undefined;
470 | }
471 | }
472 |
473 | /**
474 | * 批量添加闪卡
475 | * @param {*} ids
476 | * @param {*} deckId 目标牌组Id
477 | * @param {*} oldCardsNum 原有牌组卡牌数(可选)
478 | * @returns (若未传入原卡牌数)添加后牌组内卡牌数, (若传入)返回实际添加的卡牌数; 返回null表示请求失败
479 | */
480 | export async function addRiffCards(ids, deckId, oldCardsNum = -1) {
481 | let url = "/api/riff/addRiffCards";
482 | let postBody = {
483 | deckID: deckId,
484 | blockIDs: ids
485 | };
486 | let response = await postRequest(postBody, url);
487 | if (response.code == 0 && response.data != null && "size" in response.data) {
488 | if (oldCardsNum < 0) {
489 | return response.data.size;
490 | }else{
491 | return response.data.size - oldCardsNum;
492 | }
493 | }
494 | warnPush("添加闪卡出错", response);
495 | return null;
496 | }
497 |
498 | /**
499 | * 批量移除闪卡
500 | * @param {*} ids
501 | * @param {*} deckId 目标牌组Id
502 | * @param {*} oldCardsNum 原有牌组卡牌数(可选)
503 | * @returns (若未传入原卡牌数)移除后牌组内卡牌数, (若传入)返回实际移除的卡牌数; 返回null表示请求失败
504 | */
505 | export async function removeRiffCards(ids, deckId, oldCardsNum = -1) {
506 | let url = "/api/riff/removeRiffCards";
507 | let postBody = {
508 | deckID: deckId,
509 | blockIDs: ids
510 | };
511 | let response = await postRequest(postBody, url);
512 | if (response.code == 0 && response.data != null && "size" in response.data) {
513 | if (oldCardsNum < 0) {
514 | return response.data.size;
515 | }else{
516 | return oldCardsNum - response.data.size;
517 | }
518 | }
519 | warnPush("移除闪卡出错", response);
520 | return null;
521 | }
522 |
523 | /**
524 | * 获取全部牌组信息
525 | * @returns 返回数组
526 | * [{"created":"2023-01-05 20:29:48",
527 | * "id":"20230105202948-xn12hz6",
528 | * "name":"Default Deck",
529 | * "size":1,
530 | * "updated":"2023-01-19 21:48:21"}]
531 | */
532 | export async function getRiffDecks() {
533 | let url = "/api/riff/getRiffDecks";
534 | let response = await postRequest({}, url);
535 | if (response.code == 0 && response.data != null) {
536 | return response.data;
537 | }
538 | return new Array();
539 | }
540 |
541 | /**
542 | * 获取文件内容或链接信息
543 | * @param {*} blockid 获取的文件id
544 | * @param {*} size 获取的块数
545 | * @param {*} mode 获取模式,0为获取html;1为
546 | */
547 | export async function getDoc(blockid, size = 5, mode = 0) {
548 | let url = "/api/filetree/getDoc";
549 | let response = await postRequest({id: blockid, mode: mode, size: size}, url);
550 | if (response.code == 0 && response.data != null) {
551 | return response.data;
552 | }
553 | return undefined;
554 | }
555 |
556 | /**
557 | * 获取文档导出预览
558 | * @param {*} docid
559 | * @returns
560 | */
561 | export async function getDocPreview(docid) {
562 | let url = "/api/export/preview";
563 | let response = await postRequest({id: docid}, url);
564 | if (response.code == 0 && response.data != null) {
565 | return response.data.html;
566 | }
567 | return "";
568 | }
569 | /**
570 | * 删除文档
571 | * @param {*} notebookid 笔记本id
572 | * @param {*} path 文档所在路径
573 | * @returns
574 | */
575 | export async function removeDocAPI(notebookid, path) {
576 | let url = "/api/filetree/removeDoc";
577 | let response = await postRequest({"notebook": notebookid, "path": path}, url);
578 | if (response.code == 0) {
579 | return response.code;
580 | }
581 | warnPush("删除文档时发生错误", response.msg);
582 | return response.code;
583 | }
584 | /**
585 | * 重命名文档
586 | * @param {*} notebookid 笔记本id
587 | * @param {*} path 文档所在路径
588 | * @param {*} title 新文档名
589 | * @returns
590 | */
591 | export async function renameDocAPI(notebookid, path, title) {
592 | let url = "/api/filetree/renameDoc";
593 | let response = await postRequest({"notebook": notebookid, "path": path, "title": title}, url);
594 | if (response.code == 0) {
595 | return response.code;
596 | }
597 | warnPush("重命名文档时发生错误", response.msg);
598 | return response.code;
599 | }
600 |
601 | export function isDarkMode() {
602 | if (window.top.siyuan) {
603 | return window.top.siyuan.config.appearance.mode == 1 ? true : false;
604 | } else {
605 | let isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches;
606 | return isDarkMode;
607 | }
608 | }
609 |
610 | /**
611 | * 通过markdown创建文件
612 | * @param {*} notebookid 笔记本id
613 | * @param {*} hpath 示例 /父文档1/父文档2/你要新建的文档名
614 | * @param {*} md
615 | * @returns
616 | */
617 | export async function createDocWithMdAPI(notebookid, hpath, md) {
618 | let url = "/api/filetree/createDocWithMd";
619 | let response = await postRequest({"notebook": notebookid, "path": hpath, "markdown": md}, url);
620 | if (response.code == 0 && response.data != null) {
621 | return response.data.id;
622 | }
623 | return null;
624 | }
625 |
626 | /**
627 | *
628 | * @param {*} notebookid
629 | * @param {*} path 待创建的新文档path,即,最后应当为一个随机的id.sy
630 | * @param {*} title 【可选】文档标题
631 | * @param {*} contentMd 【可选】markdown格式的内容
632 | * @returns
633 | */
634 | export async function createDocWithPath(notebookid, path, title = "Untitled", contentMd = "") {
635 | let url = "/api/filetree/createDoc";
636 | let response = await postRequest({"notebook": notebookid, "path": path, "md": contentMd, "title": title}, url);
637 | if (response.code == 0) {
638 | return true;
639 | }
640 | return false;
641 | }
642 |
643 | /**
644 | * 将对象保存为JSON文件
645 | * @param {*} path
646 | * @param {*} object
647 | * @param {boolean} format
648 | * @returns
649 | */
650 | export async function putJSONFile(path, object, format = false) {
651 | const url = "/api/file/putFile";
652 | const pathSplited = path.split("/");
653 | let fileContent = "";
654 | if (format) {
655 | fileContent = JSON.stringify(object, null, 4);
656 | } else {
657 | fileContent = JSON.stringify(object);
658 | }
659 | // File的文件名实际上无关,但这里考虑到兼容,将上传文件按照路径进行了重命名
660 | const file = new File([fileContent], pathSplited[pathSplited.length - 1], {type: "text/plain"});
661 | const data = new FormData();
662 | data.append("path", path);
663 | data.append("isDir", "false");
664 | data.append("modTime", new Date().valueOf().toString());
665 | data.append("file", file);
666 | return fetch(url, {
667 | body: data,
668 | method: 'POST',
669 | headers: {
670 | "Authorization": "Token "+ getToken()
671 | }
672 | }).then((response) => {
673 | return response.json();
674 | });
675 | }
676 |
677 | /**
678 | * 从JSON文件中读取对象
679 | * @param {*} path
680 | * @returns
681 | */
682 | export async function getJSONFile(path) {
683 | const url = "/api/file/getFile";
684 | let response = await postRequest({"path": path}, url);
685 | if (response.code == 404) {
686 | return null;
687 | }
688 | return response;
689 | }
690 |
691 | export async function getFileAPI(path) {
692 | const url = "/api/file/getFile";
693 | let data = {"path": path};
694 | let result;
695 | let response = await fetch(url, {
696 | body: JSON.stringify(data),
697 | method: 'POST',
698 | headers: {
699 | "Authorization": "Token "+ getToken(),
700 | "Content-Type": "application/json"
701 | }
702 | });
703 | result = await response.text();
704 | try {
705 | let jsonresult = JSON.parse(result);
706 | if (jsonresult.code == 404) {
707 | return null;
708 | }
709 | return result;
710 | } catch(err) {
711 |
712 | }
713 | return result;
714 | }
715 |
716 | /**
717 | * 列出工作空间下的文件
718 | * @param {*} path 例如"/data/20210808180117-6v0mkxr/20200923234011-ieuun1p.sy"
719 | * @returns isDir, isSymlink, name三个属性
720 | */
721 | export async function listFileAPI(path) {
722 | const url = "/api/file/readDir";
723 | let response = await postRequest({"path": path}, url);
724 | if (response.code == 0) {
725 | return response.data;
726 | }
727 | return [];
728 | }
729 |
730 | export async function removeFileAPI(path) {
731 | const url = "/api/file/removeFile";
732 | let response = await postRequest({"path": path}, url);
733 | if (response.code == 0) {
734 | return true;
735 | } else {
736 | return false;
737 | }
738 | }
739 |
740 | export async function getDocInfo(id) {
741 | let data = {
742 | "id": id
743 | };
744 | let url = `/api/block/getDocInfo`;
745 | return getResponseData(postRequest(data, url));
746 | }
747 |
748 | /**
749 | * 反向链接面板用的API(标注有T,该API不是正式API)
750 | * @param id
751 | * @param sort 反链结果排序方式 字母0/1、自然4/5创建9/10,修改2/3
752 | * @param msort
753 | * @param k
754 | * @param mk 看起来是提及部分的关键词
755 | * @returns
756 | */
757 | export async function getBackLink2T(id, sort = "3", msort= "3", k = "", mk = "") {
758 | let data = {
759 | "id": id,
760 | "sort": sort,
761 | "msort": msort,
762 | "k": k,
763 | "mk": mk
764 | };
765 | let url = `/api/ref/getBacklink2`;
766 | return getResponseData(postRequest(data, url));
767 | }
768 |
769 | export async function getTreeStat(id:string) {
770 | let data = {
771 | "id": id
772 | };
773 | let url = `/api/block/getTreeStat`;
774 | return getResponseData(postRequest(data, url));
775 | }
776 |
777 | let isMobileRecentResult = null;
778 | export function isMobile() {
779 | if (isMobileRecentResult != null) {
780 | return isMobileRecentResult;
781 | }
782 | if (window.top.document.getElementById("sidebar")) {
783 | isMobileRecentResult = true;
784 | return true;
785 | } else {
786 | isMobileRecentResult = false;
787 | return false;
788 | }
789 | };
790 |
791 | export function getBlockBreadcrumb(blockId: string, excludeTypes: string[] = []) {
792 | let data = {
793 | "id": blockId,
794 | "excludeTypes": excludeTypes
795 | };
796 | let url = `/api/block/getBlockBreadcrumb`;
797 | return getResponseData(postRequest(data, url));
798 | }
799 |
800 | export async function getHPathById(docId:string): Promise {
801 | let data = {
802 | "id": docId
803 | }
804 | const url = "/api/filetree/getHPathByID";
805 | return getResponseData(postRequest(data, url)) as Promise;
806 | }
807 |
808 | /**
809 | * 批量设置属性
810 | * @param {*} blockAttrs 数组,每一个元素为对象,包含 id 和 attrs两个属性值,attrs为对象,其属性和属性值即为 attr-key: attr-value
811 | * @ref https://github.com/siyuan-note/siyuan/issues/10337
812 | */
813 | export async function batchSetBlockAtrs(blockAttrs: string) {
814 | let url = "/api/attr/batchSetBlockAttrs";
815 | let postBody = {
816 | blockAttrs: blockAttrs,
817 | };
818 | let response = await postRequest(postBody, url);
819 | if (response.code == 0 && response.data != null) {
820 | return response.data;
821 | }
822 | return null;
823 | }
824 |
825 | export const DOC_SORT_TYPES = {
826 | FILE_NAME_ASC: 0,
827 | FILE_NAME_DESC: 1,
828 | NAME_NAT_ASC: 4,
829 | NAME_NAT_DESC: 5,
830 | CREATED_TIME_ASC: 9,
831 | CREATED_TIME_DESC: 10,
832 | MODIFIED_TIME_ASC: 2,
833 | MODIFIED_TIME_DESC: 3,
834 | REF_COUNT_ASC: 7,
835 | REF_COUNT_DESC: 8,
836 | DOC_SIZE_ASC: 11,
837 | DOC_SIZE_DESC: 12,
838 | SUB_DOC_COUNT_ASC: 13,
839 | SUB_DOC_COUNT_DESC: 14,
840 | CUSTOM_SORT: 6,
841 | FOLLOW_DOC_TREE: 255, // 插件内部定义的”跟随文档树“
842 | FOLLOW_DOC_TREE_ORI: 15, // 官方对于”跟随文档树“的定义
843 | UNASSIGNED: 256,
844 | };
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------