From 31cab586a3e38d1f3cb7ff8413a9f93b8b970df3 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Fri, 24 May 2019 12:02:31 +0800 Subject: [PATCH 001/400] Format source. --- src/background.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/background.js b/src/background.js index 269cc1926..e538f5aeb 100644 --- a/src/background.js +++ b/src/background.js @@ -83,18 +83,17 @@ menu.OnClicked( ( info, tab ) => { * Listen runtime message, include: `corb` */ browser.runtime.onMessage.addListener( function( request, sender, sendResponse ) { - if ( request.type == msg.MESSAGE_ACTION.CORB ) { - $.ajax( request.value.settings ) - .done( result => { - sendResponse({ done: result }); - }) - .fail( ( jqXHR, textStatus, errorThrown ) => { - sendResponse({ fail: { jqXHR, textStatus, errorThrown }}); - }); - } - return true; + if ( request.type == msg.MESSAGE_ACTION.CORB ) { + $.ajax( request.value.settings ) + .done( result => { + sendResponse({ done: result }); + }) + .fail( ( jqXHR, textStatus, errorThrown ) => { + sendResponse({ fail: { jqXHR, textStatus, errorThrown }}); + }); } -); + return true; +}); /** * Listen runtime message, include: `shortcuts` `browser_action` From 7a7e33acde9e221840b7e109604ca0415d8f4c17 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Fri, 24 May 2019 15:45:51 +0800 Subject: [PATCH 002/400] Add webdav library. --- src/vender/webdav.js | 164 +++++++++++++++++++++++++++++++++++++++++++ webpack.config.js | 1 + 2 files changed, 165 insertions(+) create mode 100644 src/vender/webdav.js diff --git a/src/vender/webdav.js b/src/vender/webdav.js new file mode 100644 index 000000000..65c800536 --- /dev/null +++ b/src/vender/webdav.js @@ -0,0 +1,164 @@ +/* A simple WebDav implementation in JavaScript + https://github.com/aslakhellesoy/webdavjs @license MIT +*/ +var WebDAV = { + GET: function(url, callback) { + return this.request('GET', url, {}, null, 'text', callback); + }, + + PROPFIND: function(url, callback) { + return this.request('PROPFIND', url, { + Depth: "1" + }, null, 'xml', callback); + }, + + MKCOL: function(url, callback) { + return this.request('MKCOL', url, {}, null, 'text', callback); + }, + + DELETE: function(url, callback) { + return this.request('DELETE', url, {}, null, 'text', callback); + }, + + PUT: function(url, data, callback) { + return this.request('PUT', url, {}, data, 'text', callback); + }, + + Author: function(user, password) { + this.user = user; + this.password = password; + }, + + request: function(verb, url, headers, data, type, callback) { + var xhr = new XMLHttpRequest(); + var body = function() { + var b = xhr.responseText; + if (type == 'xml') { + var xml = xhr.responseXML; + if (xml) { + b = xml.firstChild.nextSibling ? xml.firstChild.nextSibling : xml.firstChild; + } + } + return b; + }; + + if (callback) { + xhr.onreadystatechange = function() { + if (xhr.readyState === XMLHttpRequest.DONE && verb == "PROPFIND") { + var b = body(); + if (b) { + callback(b); + } + } else if (xhr.readyState === XMLHttpRequest.DONE) { + callback(xhr); + } + }; + } + xhr.open(verb, url, !! callback); + xhr.setRequestHeader("Content-Type", "text/xml; charset=UTF-8"); + this.user && this.password && + xhr.setRequestHeader("Authorization", "Basic " + btoa(this.user + ":" + this.password)) + for (var header in headers) { + xhr.setRequestHeader(header, headers[header]); + } + xhr.send(data); + + if (!callback) { + return body(); + } + } +}; + +// An Object-oriented API around WebDAV. +WebDAV.Fs = function(rootUrl, user, password) { + WebDAV.Author(user, password); + this.rootUrl = rootUrl; + var fs = this; + + this.file = function(href) { + this.type = 'file'; + + this.url = fs.urlFor(href); + + this.name = fs.nameFor(this.url); + + this.read = function(callback) { + return WebDAV.GET(this.url, callback); + }; + + this.write = function(data, callback) { + return WebDAV.PUT(this.url, data, callback); + }; + + this.rm = function(callback) { + return WebDAV.DELETE(this.url, callback); + }; + + return this; + }; + + this.dir = function(href) { + this.type = 'dir'; + + this.url = fs.urlFor(href); + + this.name = fs.nameFor(this.url); + + this.children = function(callback) { + var childrenFunc = function(doc) { + if (doc.childNodes == null) { + throw ('No such directory: ' + url); + } + var result = []; + // Start at 1, because the 0th is the same as self. + for (var i = 1; i < doc.childNodes.length; i++) { + var response = doc.childNodes[i]; + var href = decodeURI( response.getElementsByTagName('d:href')[0].firstChild.nodeValue.replace(/\/$/, '')); + var propstat = response.getElementsByTagName('d:propstat')[0]; + var prop = propstat.getElementsByTagName('d:prop')[0]; + var resourcetype = prop.getElementsByTagName('d:resourcetype')[0]; + var collection = resourcetype.getElementsByTagName('d:collection')[0]; + + if (collection) { + result[i - 1] = new fs.dir(href); + } else { + result[i - 1] = new fs.file(href); + } + } + return result; + }; + + if (callback) { + WebDAV.PROPFIND(this.url, function(doc) { + callback(childrenFunc(doc)); + }); + } else { + return childrenFunc(WebDAV.PROPFIND(this.url)); + } + }; + + this.rm = function(callback) { + return WebDAV.DELETE(this.url, callback); + }; + + this.mkdir = function(callback) { + return WebDAV.MKCOL(this.url, callback); + }; + + return this; + }; + + this.urlFor = function(href) { + return (/^http/.test(href) ? href : this.rootUrl + href); + }; + + this.nameFor = function(url) { + return url.replace(/.*\/(.*)/, '$1'); + }; + + return this; +}; + +if (typeof module !== 'undefined') { + module.exports = WebDAV; +} \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index d90c1a1a0..60262927b 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -234,6 +234,7 @@ const webpack = require( 'webpack' ), dom2image : __dirname + '/src/vender/dom2image.min.js', filesaver : __dirname + '/src/vender/filesaver.min.js', instapaper : __dirname + '/src/vender/instapaper.js', + webdav : __dirname + '/src/vender/webdav.js', util : __dirname + '/src/service/util.js', local : __dirname + '/src/service/local.js', From 7db10fc1f293e1bc04e86aa153d1fa925f6ee3b9 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Fri, 24 May 2019 15:46:33 +0800 Subject: [PATCH 003/400] Add jianguo secret. --- src/service/storage.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/service/storage.js b/src/service/storage.js index 713bae1bb..8fa75746e 100644 --- a/src/service/storage.js +++ b/src/service/storage.js @@ -217,6 +217,11 @@ let current = {}, access_token : "", folder_id : "", }, + "jianguo" : { + username : "", + password : "", + access_token : "", + }, }; //stcode = -1; From e3a07143b9a81c9ddc3053c2547f86e9d0d6c9c8 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Fri, 24 May 2019 15:47:03 +0800 Subject: [PATCH 004/400] Add new message: WebDAV. --- src/service/message.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/service/message.js b/src/service/message.js index 3e7be4139..c5eb9b98f 100644 --- a/src/service/message.js +++ b/src/service/message.js @@ -34,6 +34,8 @@ const action = { temp_site : "temp_site", // corb CORB : "corb", + // webdav + WebDAV : "WebDAV", }; /** From 902d50b33a9559a002c00d7cb2556c724c98291c Mon Sep 17 00:00:00 2001 From: Kenshin Date: Fri, 24 May 2019 15:47:27 +0800 Subject: [PATCH 005/400] Add jianguo class. --- src/service/export.js | 58 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/src/service/export.js b/src/service/export.js index 8b230b928..85ad51032 100644 --- a/src/service/export.js +++ b/src/service/export.js @@ -982,6 +982,57 @@ class Kindle { } } +/** + * Onenote + * + * @class + */ +class Jianguo { + + get id() { return "jianguo"; } + get name() { return name( this.id ); } + + get url() { + return "https://dav.jianguoyun.com/dav/"; + } + + get root() { + return "SimpRead"; + } + + get folder() { + return "md"; + } + + Auth( user, password, callback ) { + browser.runtime.sendMessage( msg.Add( msg.MESSAGE_ACTION.WebDAV, { + url: this.url, + user, + password, + method: { + type: "folder", + root: this.root, + folder: this.folder, + }, + }), callback ); + } + + Add( user, password, name, content, callback ) { + browser.runtime.sendMessage( msg.Add( msg.MESSAGE_ACTION.WebDAV, { + url: this.url, + user, + password, + method: { + type: "file", + root: this.root, + folder: this.folder, + name, + content + }, + }), callback ); + } +} + /** * Get name * @@ -996,8 +1047,10 @@ function name( type ) { return "印象笔记"; } else if ( type == "gdrive" ) { return "Google 云端硬盘"; + } else if ( type == "jianguo" ) { + return "坚果云"; } - return type; +return type; } /** @@ -1074,6 +1127,7 @@ const dropbox = new Dropbox(), evernote = new Evernote(), onenote = new Onenote(), gdrive = new GDrive(), + jianguo = new Jianguo(), kindle = new Kindle(); export { @@ -1085,7 +1139,7 @@ export { prueDownload as PrDownload, unlink as Unlink, name as Name, - dropbox, pocket, instapaper, linnk, evernote, onenote, gdrive, + dropbox, pocket, instapaper, linnk, evernote, onenote, gdrive, jianguo, kindle, mdWrapper as MDWrapper, serviceCallback as svcCbWrapper, From 93aa5682b04af233d15aa1c4095f276bf9d8347f Mon Sep 17 00:00:00 2001 From: Kenshin Date: Fri, 24 May 2019 15:48:06 +0800 Subject: [PATCH 006/400] Add runtime: webdav and logic. --- src/background.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/background.js b/src/background.js index e538f5aeb..b5fa9dc15 100644 --- a/src/background.js +++ b/src/background.js @@ -7,6 +7,7 @@ import {browser} from 'browser'; import * as ver from 'version'; import * as menu from 'menu'; import * as watch from 'watch'; +import * as WebDAV from 'webdav'; import PureRead from 'puread'; @@ -95,6 +96,29 @@ browser.runtime.onMessage.addListener( function( request, sender, sendResponse ) return true; }); +/** + * Listen runtime message, include: `webdav` + */ +browser.runtime.onMessage.addListener( function( request, sender, sendResponse ) { + if ( request.type == msg.MESSAGE_ACTION.WebDAV ) { + const { url, user, password, method } = request.value; + const dav = new WebDAV.Fs( url, user, password ); + sendResponse({ done: "result" }); + if ( method.type == "folder" ) { + dav.dir( method.root ).mkdir( result => { + dav.dir( method.root + "/" + method.folder ).mkdir( result => { + sendResponse({ done: result }); + }); + }) + } else if ( method.type == "file" ) { + dav.file( method.root + "/" + method.folder + "/" + method.name ).write( method.content, result => { + sendResponse({ done: result, status: result.status }); + }); + } + } + //return true; +}); + /** * Listen runtime message, include: `shortcuts` `browser_action` */ From a560721e0d2c5b1536f936250935fedc14831ac4 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Fri, 24 May 2019 15:48:56 +0800 Subject: [PATCH 007/400] Add jianguo icon and workflow. --- src/assets/images/jianguo_icon.png | Bin 0 -> 497 bytes src/read/controlbar.jsx | 2 +- src/service/config.js | 5 +++++ 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 src/assets/images/jianguo_icon.png diff --git a/src/assets/images/jianguo_icon.png b/src/assets/images/jianguo_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..497993df6eee27cd9f05e3a544d502e9cac077be GIT binary patch literal 497 zcmV*`RGz1;#n0;hnBYWl7nwSb5i1?~bzfXl!(@DBI_JXP1KD5ZdiI0q~MXEO03o$tU8 z;F0>I$e<7q5%++Hz(8#b{u=xN-l~^6?e_s9;x>>@bF86wtJ#`*zICDvkX^&iJ&NbL zi|VcXrxP#_>@D`-LE7?5JzNI(2^{KCxOLl@`X){6c@Pnk!0JB`PZHzm>;DNDQrFu6 z=_ew70|)x_Vp}~}mV@@Ig&gpb#(z-02grqFyfp3y+;1Y};MNB01@&=8WY_kA_x zux(WJgDD`D?K)3V1DaMJ7agXuqh(F!IdHPXla$nJ>dP`uYg=X(vRPoJ 0 && type.startsWith( "share" ) || - [ "fullscreen", "save", "markdown", "png", "epub", "pdf", "kindle", "temp", "html", "dropbox", "pocket", "instapaper", "linnk", "yinxiang","evernote", "onenote", "gdrive" ].includes( type )) { + [ "fullscreen", "save", "markdown", "png", "epub", "pdf", "kindle", "temp", "html", "dropbox", "pocket", "instapaper", "linnk", "yinxiang","evernote", "onenote", "gdrive", "jianguo" ].includes( type )) { const [ title, desc, content ] = [ $( "sr-rd-title" ).text().trim(), $( "sr-rd-desc" ).text().trim(), $( "sr-rd-content" ).html().trim() ]; output.Action( type, title, desc, content ); } diff --git a/src/service/config.js b/src/service/config.js index 08ee4efd0..1832b4a5e 100644 --- a/src/service/config.js +++ b/src/service/config.js @@ -313,6 +313,11 @@ const readItems = { "icon" : ss.IconPath("gdrive_icon"), "color": "#00BCD4", }, + "jianguo" : { + "name" : "保存到 坚果云", + "icon" : ss.IconPath("jianguo_icon"), + "color": "#00BCD4", + }, "kindle" : { "name" : "保存到 Kindle", "icon" : ss.IconPath("kindle_icon"), From 214dc36e34a52a5875dbf799f1f60fc949299d6b Mon Sep 17 00:00:00 2001 From: Kenshin Date: Fri, 24 May 2019 15:50:06 +0800 Subject: [PATCH 008/400] Add jianguo authorization logic. --- src/module/authorize.jsx | 56 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/src/module/authorize.jsx b/src/module/authorize.jsx index 292f7e10b..aa57ef4d7 100644 --- a/src/module/authorize.jsx +++ b/src/module/authorize.jsx @@ -20,6 +20,10 @@ export default class Auth extends React.Component { instapaper: { username: "", password: "", + }, + jianguo: { + username: "", + password: "", } } @@ -27,11 +31,12 @@ export default class Auth extends React.Component { secret : undefined, linnk : undefined, instapaper : undefined, + jianguo: undefined, } onChange( state, value, flag ) { let notify; - const { dropbox, pocket, instapaper, linnk, evernote, onenote, gdrive } = exp, + const { dropbox, pocket, instapaper, linnk, evernote, onenote, gdrive, jianguo } = exp, clear = ( id, name ) => { Object.keys( storage.secret[id] ).forEach( item => storage.secret[id][item] = "" ); storage.Safe( ()=> { @@ -42,10 +47,12 @@ export default class Auth extends React.Component { success = ( id, name, data ) => { notify && notify.complete(); Object.keys( data ).forEach( item => storage.secret[id][item] = data[item] ); + id == "jianguo" && ( storage.secret[id]["access_token"] = { username: data.username, password: data.password }); storage.Safe( () => { new Notify().Render( `已成功授权 ${name} 。` ); id == "linnk" && this.setState({ secret: storage.secret, linnk: false }); id == "instapaper" && this.setState({ secret: storage.secret, instapaper: false }); + id == "jianguo" && this.setState({ secret: storage.secret, jianguo: false }); if ( location.hash.startsWith( "#labs?auth=" ) ) { new Notify().Render( "3 秒钟将会关闭此页面..." ); setTimeout( () => { @@ -72,6 +79,11 @@ export default class Auth extends React.Component { return; } + if ( state == "jianguo" && !flag && !storage.secret.jianguo.username ) { + this.setState({ jianguo: !this.state.jianguo }); + return; + } + if ( !value ) { state == "pocket" && $( this.refs.pocket_tags ).velocity( value ? "slideDown" : "slideUp" ); if ( state == "linnk" ) { @@ -82,6 +94,10 @@ export default class Auth extends React.Component { this.props.instapaper.username = ""; this.props.instapaper.password = ""; } + if ( state == "jianguo" ) { + this.props.jianguo.username = ""; + this.props.jianguo.password = ""; + } clear( state, exp.Name( state )); return; } @@ -170,6 +186,13 @@ export default class Auth extends React.Component { }); }).fail( error => failed( error, gdrive.id, gdrive.name )); break; + case "jianguo": + jianguo.Auth( this.props.jianguo.username, this.props.jianguo.password, result => { + if ( result && result.done ) { + success( "jianguo", "坚果云", { username: this.props.jianguo.username, password: this.props.jianguo.password } ); + } else failed( result.error, jianguo.id, jianguo.name ); + }); + break; } } @@ -187,6 +210,10 @@ export default class Auth extends React.Component { this.props.instapaper[state] = value; } + jianguoOnChange( state, value ) { + this.props.jianguo[state] = value; + } + componentWillReceiveProps( nextProps ) { this.setState({ secret: storage.secret }) } @@ -305,6 +332,33 @@ export default class Auth extends React.Component { label={ this.state.secret.gdrive.access_token ? "已授权 Google 云端硬盘,是否取消授权?" : "是否连接并授权 Google 云端硬盘 ?" } onChange={ (s)=>this.onChange( "gdrive", s ) } /> + this.onChange( "jianguo", s ) } /> + + { this.state.jianguo && +
+
+ this.jianguoOnChange( "username", evt.target.value ) } + /> + this.jianguoOnChange( "password", evt.target.value ) } + /> +
+ +
} + ; } From d3fac01b0c730e3c589380fbee3652da10f0800e Mon Sep 17 00:00:00 2001 From: Kenshin Date: Fri, 24 May 2019 15:50:31 +0800 Subject: [PATCH 009/400] Add export to jianguo workflow. --- src/service/output.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/service/output.js b/src/service/output.js index 1e5cfb9ce..e8f2754b9 100644 --- a/src/service/output.js +++ b/src/service/output.js @@ -138,8 +138,8 @@ function action( type, title, desc, content ) { } break; } - } else if ( [ "dropbox", "pocket", "instapaper", "linnk", "yinxiang","evernote", "onenote", "gdrive" ].includes( type ) ) { - const { dropbox, pocket, instapaper, linnk, evernote, onenote, gdrive } = exp, + } else if ( [ "dropbox", "pocket", "instapaper", "linnk", "yinxiang","evernote", "onenote", "gdrive", "jianguo" ].includes( type ) ) { + const { dropbox, pocket, instapaper, linnk, evernote, onenote, gdrive, jianguo } = exp, id = type == "yinxiang" ? "evernote" : type; storage.Statistics( "service", type ); const service = type => { @@ -198,6 +198,15 @@ function action( type, title, desc, content ) { gdrive.Add( "file",( result, error ) => exp.svcCbWrapper( result, error, gdrive.name, type, new Notify() ), gdrive.CreateFile( `${title}.md`, result )); }); break; + case "jianguo": + exp.MDWrapper( util.ClearMD( content) , undefined, new Notify() ).done( markdown => { + jianguo.Add( storage.secret.jianguo.username, storage.secret.jianguo.password, encodeURI( `${title}.md` ), markdown, result => { + //if ( result && result.done ) { + //} else failed( result.error, jianguo.id, jianguo.name ); + exp.svcCbWrapper( result, undefined, jianguo.name, type, new Notify() ); + }); + }); + break; } }; From afc5c999b895347a66a757a75e3942a6d268bea2 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Sat, 25 May 2019 10:25:02 +0800 Subject: [PATCH 010/400] Optimize export jianguo title logic. --- src/service/output.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/service/output.js b/src/service/output.js index e8f2754b9..c04be070a 100644 --- a/src/service/output.js +++ b/src/service/output.js @@ -200,7 +200,8 @@ function action( type, title, desc, content ) { break; case "jianguo": exp.MDWrapper( util.ClearMD( content) , undefined, new Notify() ).done( markdown => { - jianguo.Add( storage.secret.jianguo.username, storage.secret.jianguo.password, encodeURI( `${title}.md` ), markdown, result => { + title = title.replace( /[|@!#$%^&*()<>/,.+=\\]/ig, "-" ); + jianguo.Add( storage.secret.jianguo.username, storage.secret.jianguo.password, `${title}.md`, markdown, result => { //if ( result && result.done ) { //} else failed( result.error, jianguo.id, jianguo.name ); exp.svcCbWrapper( result, undefined, jianguo.name, type, new Notify() ); From 76cba281b0d2ccb8bbb5fba4f2bdd5eb31f69592 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Sat, 25 May 2019 13:32:46 +0800 Subject: [PATCH 011/400] Format source. --- src/background.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/background.js b/src/background.js index b5fa9dc15..3ce32e4d3 100644 --- a/src/background.js +++ b/src/background.js @@ -103,7 +103,6 @@ browser.runtime.onMessage.addListener( function( request, sender, sendResponse ) if ( request.type == msg.MESSAGE_ACTION.WebDAV ) { const { url, user, password, method } = request.value; const dav = new WebDAV.Fs( url, user, password ); - sendResponse({ done: "result" }); if ( method.type == "folder" ) { dav.dir( method.root ).mkdir( result => { dav.dir( method.root + "/" + method.folder ).mkdir( result => { From 00aa9c895e7aa1ca4d99adad56a7b3f0327ebef6 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Sat, 25 May 2019 13:41:04 +0800 Subject: [PATCH 012/400] Optimize export failed logic. --- src/service/output.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/service/output.js b/src/service/output.js index c04be070a..23a0055e8 100644 --- a/src/service/output.js +++ b/src/service/output.js @@ -202,9 +202,10 @@ function action( type, title, desc, content ) { exp.MDWrapper( util.ClearMD( content) , undefined, new Notify() ).done( markdown => { title = title.replace( /[|@!#$%^&*()<>/,.+=\\]/ig, "-" ); jianguo.Add( storage.secret.jianguo.username, storage.secret.jianguo.password, `${title}.md`, markdown, result => { - //if ( result && result.done ) { - //} else failed( result.error, jianguo.id, jianguo.name ); - exp.svcCbWrapper( result, undefined, jianguo.name, type, new Notify() ); + let error = undefined; + if ( result && ( result.status == 201 || result.status == 204 )) { + } else error = "导出到坚果云失败,请稍后再试。"; + exp.svcCbWrapper( result, error, jianguo.name, type, new Notify() ); }); }); break; From 512d549cc578d9ac404f0cd943dbaf6c9fe93bc3 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Sat, 25 May 2019 13:44:31 +0800 Subject: [PATCH 013/400] Format source. --- src/service/output.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/service/output.js b/src/service/output.js index 23a0055e8..475643c46 100644 --- a/src/service/output.js +++ b/src/service/output.js @@ -203,8 +203,9 @@ function action( type, title, desc, content ) { title = title.replace( /[|@!#$%^&*()<>/,.+=\\]/ig, "-" ); jianguo.Add( storage.secret.jianguo.username, storage.secret.jianguo.password, `${title}.md`, markdown, result => { let error = undefined; - if ( result && ( result.status == 201 || result.status == 204 )) { - } else error = "导出到坚果云失败,请稍后再试。"; + if ( result && ( result.status != 201 && result.status != 204 )) { + error = "导出到坚果云失败,请稍后再试。"; + } exp.svcCbWrapper( result, error, jianguo.name, type, new Notify() ); }); }); From 10cb3b540454ecff188a9891de0fc421a7bf7a4a Mon Sep 17 00:00:00 2001 From: Kenshin Date: Sat, 25 May 2019 13:54:42 +0800 Subject: [PATCH 014/400] Add jianguo unlink url. --- src/service/export.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/service/export.js b/src/service/export.js index 85ad51032..a576fe773 100644 --- a/src/service/export.js +++ b/src/service/export.js @@ -115,6 +115,7 @@ function unlink( id ) { "yinxiang": "https://app.yinxiang.com/AuthorizedServices.action", "onenote" : "https://account.live.com/consent/Manage", "gdrive" : "https://drive.google.com/drive/my-drive", + "jianguo" : "http://help.jianguoyun.com/?p=2064", "linnk" : "https://linnk.net/", } return content[id] From 6447217114bf432df89f9f5763b29bde3d180dc2 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Sat, 25 May 2019 13:54:55 +0800 Subject: [PATCH 015/400] Format source. --- src/background.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/background.js b/src/background.js index 3ce32e4d3..aa23ce838 100644 --- a/src/background.js +++ b/src/background.js @@ -106,7 +106,7 @@ browser.runtime.onMessage.addListener( function( request, sender, sendResponse ) if ( method.type == "folder" ) { dav.dir( method.root ).mkdir( result => { dav.dir( method.root + "/" + method.folder ).mkdir( result => { - sendResponse({ done: result }); + sendResponse({ done: result, status: result.status }); }); }) } else if ( method.type == "file" ) { From 83c440be0f7b02e7b55dae1f9cd52e85ff990b76 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Sat, 25 May 2019 13:55:14 +0800 Subject: [PATCH 016/400] Add jianguo auth failed logic. --- src/module/authorize.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/module/authorize.jsx b/src/module/authorize.jsx index aa57ef4d7..e2eddc656 100644 --- a/src/module/authorize.jsx +++ b/src/module/authorize.jsx @@ -188,9 +188,9 @@ export default class Auth extends React.Component { break; case "jianguo": jianguo.Auth( this.props.jianguo.username, this.props.jianguo.password, result => { - if ( result && result.done ) { - success( "jianguo", "坚果云", { username: this.props.jianguo.username, password: this.props.jianguo.password } ); - } else failed( result.error, jianguo.id, jianguo.name ); + if ( result && result.status == 401 ) { + failed( "授权错误,请重新授权。", jianguo.id, jianguo.name ); + } else success( "jianguo", "坚果云", { username: this.props.jianguo.username, password: this.props.jianguo.password } ); }); break; } From 8c8b3a25efafa0434b5acf47a54851424c8e00e9 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Sat, 25 May 2019 16:16:21 +0800 Subject: [PATCH 017/400] Add secret data structure. --- src/service/storage.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/service/storage.js b/src/service/storage.js index 8fa75746e..74eca8bde 100644 --- a/src/service/storage.js +++ b/src/service/storage.js @@ -222,6 +222,7 @@ let current = {}, password : "", access_token : "", }, + "webdav" : [] }; //stcode = -1; From 080d680f9fac7b517e75658532ca4d6317c043e5 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Sat, 25 May 2019 16:16:42 +0800 Subject: [PATCH 018/400] Add new webdav message. --- src/service/message.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/service/message.js b/src/service/message.js index c5eb9b98f..5e1ebd0b0 100644 --- a/src/service/message.js +++ b/src/service/message.js @@ -36,6 +36,7 @@ const action = { CORB : "corb", // webdav WebDAV : "WebDAV", + WebDAV2 : "WebDAV2", }; /** From a38d8455bf95694b28d03283b074f49b4ac85266 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Sat, 25 May 2019 16:17:24 +0800 Subject: [PATCH 019/400] Add webdav save and auth logic. --- src/module/authorize.jsx | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/module/authorize.jsx b/src/module/authorize.jsx index e2eddc656..cbccd5bbb 100644 --- a/src/module/authorize.jsx +++ b/src/module/authorize.jsx @@ -214,6 +214,31 @@ export default class Auth extends React.Component { this.props.jianguo[state] = value; } + webdavOnChange() { + this.state.secret.webdav = event.target.value.split("\n"); + storage.Safe( () => this.setState({ secret: storage.secret }), storage.secret ); + } + + webdavAuth() { + this.state.secret.webdav.forEach( ( item, idx ) => { + try { + item = JSON.parse(item); + if ( Object.keys( item ).join( "" ).replace( /url|name|password|user/ig, "" ) != "" ) { + throw "error"; + } + exp.webdav.Auth( item.url, item.user, item.password, result => { + if ( result && ( result.status == 201 || result.status == 405 )) { + new Notify().Render( `${item.name} 验证成功。` ); + } else { + new Notify().Render( 2, `${item.name} 授权失败,请确认用户名和密码。` ); + } + }); + } catch( error ) { + new Notify().Render( 2, `第 ${idx+1} 条数据格式错误,请重新输入。` ); + } + }); + } + componentWillReceiveProps( nextProps ) { this.setState({ secret: storage.secret }) } @@ -359,6 +384,20 @@ export default class Auth extends React.Component { } +
WebDAV
+
简悦支持任意 WebDAV 的服务,包括:Box · TeraCLOUD 等
+ this.webdavOnChange(e) } + /> +