From 8e64a3f368a1cede8f7a84a6d1a86a365110d62d Mon Sep 17 00:00:00 2001 From: Dio Woo Date: Fri, 15 May 2020 14:47:05 +0800 Subject: [PATCH 01/30] feat: save Image to Notion.so --- src/module/authorize.jsx | 5 ++ src/options/corb.js | 64 +++++++++++++++++++ src/service/export.js | 123 ++++++++++++++++++++++++++++++++++-- src/service/message.js | 3 + src/service/output.js | 1 + src/vender/notify/notify.js | 5 ++ 6 files changed, 197 insertions(+), 4 deletions(-) diff --git a/src/module/authorize.jsx b/src/module/authorize.jsx index 20168fef0..d9ea4643b 100644 --- a/src/module/authorize.jsx +++ b/src/module/authorize.jsx @@ -288,6 +288,7 @@ export default class Auth extends React.Component { state == "pocket" && ( storage.secret.pocket.tags = value.trim() ); state == "linnk" && ( storage.secret.linnk.group_name = value.trim() ); state == "notion" && ( storage.secret.notion.folder_id = value.trim() ); + state == "notion_save_image" && ( storage.secret.notion.save_image = value ); state == "youdao" && ( storage.secret.youdao.folder_id = value.trim() ); storage.Safe( () => this.setState({ secret: storage.secret }), storage.secret ); } @@ -525,6 +526,10 @@ export default class Auth extends React.Component { waves="md-waves-effect md-waves-button" onClick={ (s)=>this.notionChange() } /> } } + { this.state.secret.notion.access_token && +
+ this.save( "notion_save_image", v ) } checked={ this.state.secret.notion.save_image} label="是否将图片保存到Notion.so"> +
}
sendResponse({ done: response })) .catch( error => sendResponse({ fail: error })); + }else if( request.value.type == 'download' ) { + axios(request.value) + .then( response => sendResponse({ done: response })) + .catch( error => sendResponse({ fail: error })); } } return true; }); + +/** + * Listen runtime message, include: `notion` + */ +;(function () { + const DownLoadCache = new Map(); + + browser.runtime.onMessage.addListener(async function ( + request, + sender, + sendResponse + ) { + if (request.type == msg.MESSAGE_ACTION.NOTION_DL_IMG) { + try { + const option = request.value + const { url } = option + const dlRes = await axios({ + method: 'get', + url, + responseType: 'blob', + }) + + let blob = dlRes.data + + if (blob.type === 'image/webp') { + blob = blob.slice(0, blob.size, 'image/jpeg') + } + DownLoadCache.set(url, blob) + sendResponse({ + done: { + type: blob.type, + size: blob.size, + url, + }, + }) + } catch (err) { + sendResponse({ fail: err }) + } + } else if (request.type == msg.MESSAGE_ACTION.NOTION_UP_IMG) { + try { + const option = request.value + const { url, upUrl } = option + + const blob = DownLoadCache.get(url) + + await axios.put(upUrl, blob, { + headers: { + 'Content-Type': blob.type, + }, + }) + + DownLoadCache.delete(url) + sendResponse({ done: true }) + } catch (err) { + sendResponse({ fail: err }) + } + } + return true + }) +})() diff --git a/src/service/export.js b/src/service/export.js index 0f7311522..56f112945 100644 --- a/src/service/export.js +++ b/src/service/export.js @@ -1272,7 +1272,123 @@ class Notion { }); } - Add( title, content, callback ) { + MathImages( content ) { + const result = content.match(/!\[.*?\]\(http(.*?)\)/g) + + if( !result ){ return [] } + + const images = result + .map(o => { + const temp = /!\[.*?\]\((http.*?)\)/.exec(o); + if (temp) { + return temp[1]; + } + return ''; + }) + .filter(o => o && !~o.indexOf('secure.notion-static.com/')); + + return images + } + + DonwloadOriginImage(url) { + return new Promise((resolve, reject) => { + browser.runtime.sendMessage( + msg.Add(msg.MESSAGE_ACTION.NOTION_DL_IMG, { + url, + }), + (res) => { + if (res.done) { + resolve(res.done) + } else { + reject(res.fail) + } + } + ) + }) + } + + UploadOriginImage ( { type, size, url } ){ + return new Promise((resolve, reject) => { + this.GetFileUrl( + this.UUID(), + (urls) => { + browser.runtime.sendMessage( + msg.Add(msg.MESSAGE_ACTION.NOTION_UP_IMG, { + url: url, + upUrl: urls.signedPutUrl, + }), + (res) => { + if (res.done) { + resolve({ + from: url, + to: urls.url, + }) + } else { + resolve() + } + } + ) + }, + { + bucket: 'secure', + contentType: type, + } + ) + }) + } + + async UploadImages ( content ) { + + function escapeRegExp(string) { + return string.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&') // $& means the whole matched string + } + + const images = [...new Set(this.MathImages(content))] + const imagesCount = images.length; + let completeCount = 0; + const replacements = [] + const UploadOriginImage = this.UploadOriginImage.bind(this); + const notify = new Notify().Render({ state: "loading", content: `正在采集图片到 Notion,请稍等` }); + const updateNotify = function(){ + notify.updateContent(`正在采集图片到 Notion,请稍等 (${completeCount}/${imagesCount}) `) + } + replacements.push( + await images.reduce((prevPromise, imageUrl) => { + if (!imageUrl) return + console.log(' Notion Download Image :' + imageUrl) + return prevPromise.then((replacement) => { + if (replacement) { + replacements.push(replacement) + } + completeCount ++; + updateNotify() + return this.DonwloadOriginImage(imageUrl).then( + UploadOriginImage, + (err) => { + console.error(err) + } + ) + }) + }, Promise.resolve()) + ) + notify.complete(); + + replacements.forEach((replacement) => { + if (replacement) { + content = content.replace( + new RegExp(escapeRegExp(replacement.from),'g'), + replacement.to + ) + } + }) + + return content; + } + + async Add( title, content, callback ) { + if ( this.save_image ) { + content = await this.UploadImages(content) + } this.TempFile( this.folder_id, title, ( documentId, error ) => { console.log( 'TempFile: ', documentId ) if ( error ) { @@ -1371,14 +1487,13 @@ class Notion { }); } - GetFileUrl( name, callback ) { + GetFileUrl( name, callback, option = { bucket: 'temporary', contentType: 'text/markdown' } ) { browser.runtime.sendMessage( msg.Add( msg.MESSAGE_ACTION.AXIOS, { type: "post", url: this.url + "api/v3/getUploadFileUrl", data:{ - bucket: 'temporary', name: name, - contentType: 'text/markdown', + ...option } }), result => { if ( result && result.done ) { diff --git a/src/service/message.js b/src/service/message.js index 57f81c72c..9ca6108b9 100644 --- a/src/service/message.js +++ b/src/service/message.js @@ -53,6 +53,9 @@ const action = { // tips tips : "tips", tips_norepeat : "tips_norepeat", + // notion.so + NOTION_DL_IMG : "notion_dl_img", + NOTION_UP_IMG : "notion_up_img", }; /** diff --git a/src/service/output.js b/src/service/output.js index 80d104d20..a4da33874 100644 --- a/src/service/output.js +++ b/src/service/output.js @@ -316,6 +316,7 @@ function action( type, title, desc, content ) { corbLoader( "load", () => { notion.access_token = storage.secret.notion.access_token; notion.folder_id = storage.secret.notion.folder_id; + notion.save_image = storage.secret.notion.save_image; notion.Add( title, result.replace( /.jpeg!720/ig, '.jpeg' ), ( result, error ) => { exp.svcCbWrapper( result, error, notion.name, type, new Notify() ) }); diff --git a/src/vender/notify/notify.js b/src/vender/notify/notify.js index 9fe49119a..867810e8e 100644 --- a/src/vender/notify/notify.js +++ b/src/vender/notify/notify.js @@ -184,6 +184,11 @@ var Notify = ( function () { this.title ? $title.text( this.title ) : $title.hide(); this.content ? $content.html( this.content ) : $content.hide(); + this.updateContent = function(content){ + this.content = content; + this.content ? $content.html( this.content ) : $content.hide(); + } + if ( this.mode === MODE.modal ) { $target.addClass( "notify-modal" ); $content.addClass( "notify-modal-content" ); From 3bbcf27ba401aeaa5589fc8dd561d98be4a3fea9 Mon Sep 17 00:00:00 2001 From: Dio Woo Date: Fri, 15 May 2020 15:23:47 +0800 Subject: [PATCH 02/30] =?UTF-8?q?refactor:=20=E4=BF=AE=E6=94=B9=E5=BC=80?= =?UTF-8?q?=E5=85=B3=E6=96=87=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/module/authorize.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/module/authorize.jsx b/src/module/authorize.jsx index d9ea4643b..017d571fa 100644 --- a/src/module/authorize.jsx +++ b/src/module/authorize.jsx @@ -528,7 +528,7 @@ export default class Auth extends React.Component {
} { this.state.secret.notion.access_token &&
- this.save( "notion_save_image", v ) } checked={ this.state.secret.notion.save_image} label="是否将图片保存到Notion.so"> + this.save( "notion_save_image", v ) } checked={ this.state.secret.notion.save_image} label="将图片保存到Notion.so (速度较慢,慎重)">
}
From dbce2e1308247cf8c96c17325111380edd68edaa Mon Sep 17 00:00:00 2001 From: Dio Woo Date: Fri, 5 Jun 2020 12:47:14 +0800 Subject: [PATCH 03/30] =?UTF-8?q?fix:=20=E5=9B=BE=E7=89=87=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E5=8D=8F=E8=AE=AE=E4=B8=8D=E6=AD=A3=E7=A1=AE=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E7=9A=84=E4=B8=8B=E8=BD=BD=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/service/export.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service/export.js b/src/service/export.js index 56f112945..6aed798dd 100644 --- a/src/service/export.js +++ b/src/service/export.js @@ -1294,7 +1294,7 @@ class Notion { return new Promise((resolve, reject) => { browser.runtime.sendMessage( msg.Add(msg.MESSAGE_ACTION.NOTION_DL_IMG, { - url, + url:url.replace(/https?:/, window.location.protocol), }), (res) => { if (res.done) { From 13fa1e8a1c600a6a348d119d1299b398cc2f01f1 Mon Sep 17 00:00:00 2001 From: Dio Woo Date: Wed, 17 Jun 2020 18:37:25 +0800 Subject: [PATCH 04/30] fix: notion blocks options --- src/service/export.js | 95 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 81 insertions(+), 14 deletions(-) diff --git a/src/service/export.js b/src/service/export.js index 874b2e0af..95fd137a8 100644 --- a/src/service/export.js +++ b/src/service/export.js @@ -1248,6 +1248,17 @@ class Notion { return "https://www.notion.so/"; } + hasWriteRule(role){ + return role === 'read_and_write' || role === 'editor' + } + + getBlockName(titleArray){ + if (!titleArray) return 'Undefined' + if (Array.isArray(titleArray)) + return titleArray.map((t) => t[0]).join('') + return 'Undefined' + } + UUID() { var __extends=void 0&&(void 0).__extends||function(){var _extendStatics=function extendStatics(d,b){_extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d,b){d.__proto__=b}||function(d,b){for(var p in b)if(b.hasOwnProperty(p))d[p]=b[p]};return _extendStatics(d,b)};return function(d,b){_extendStatics(d,b);function __(){this.constructor=d}d.prototype=b===null?Object.create(b):(__.prototype=b.prototype,new __())}}();var ValueUUID=function(){function ValueUUID(_value){this._value=_value;this._value=_value}ValueUUID.prototype.asHex=function(){return this._value};return ValueUUID}();var V4UUID=function(_super){__extends(V4UUID,_super);function V4UUID(){return _super.call(this,[V4UUID._randomHex(),V4UUID._randomHex(),V4UUID._randomHex(),V4UUID._randomHex(),V4UUID._randomHex(),V4UUID._randomHex(),V4UUID._randomHex(),V4UUID._randomHex(),'-',V4UUID._randomHex(),V4UUID._randomHex(),V4UUID._randomHex(),V4UUID._randomHex(),'-','4',V4UUID._randomHex(),V4UUID._randomHex(),V4UUID._randomHex(),'-',V4UUID._oneOf(V4UUID._timeHighBits),V4UUID._randomHex(),V4UUID._randomHex(),V4UUID._randomHex(),'-',V4UUID._randomHex(),V4UUID._randomHex(),V4UUID._randomHex(),V4UUID._randomHex(),V4UUID._randomHex(),V4UUID._randomHex(),V4UUID._randomHex(),V4UUID._randomHex(),V4UUID._randomHex(),V4UUID._randomHex(),V4UUID._randomHex(),V4UUID._randomHex()].join(''))||this}V4UUID._oneOf=function(array){return array[Math.floor(array.length*Math.random())]};V4UUID._randomHex=function(){return V4UUID._oneOf(V4UUID._chars)};V4UUID._chars=['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'];V4UUID._timeHighBits=['8','9','a','b'];return V4UUID}(ValueUUID);function generateUuid(){return new V4UUID().asHex()} return generateUuid(); @@ -1261,20 +1272,76 @@ class Notion { if ( result && status == "success" ) { this.access_token = Object.values( result.recordMap.notion_user )[0].value.id; this.blocks = []; - Object.values( result.recordMap.space ).forEach( item => { - item.value.pages.forEach( ( id, idx ) => { - const block = result.recordMap.block[id]; - idx == 0 && this.blocks.push({ name: item.value.name, value: block.value.id, type: block.value.type }); - if ( block.value.type == "page" ) { - this.blocks.push({ name: "  " + ( block.value.properties ? block.value.properties.title[0][0] : "Undefined" ), value: block.value.id, type: "page" }); - } else if ( block.value.type == "collection_view_page" ) { - Object.values( result.recordMap.collection ).forEach( collection => { - collection.value.parent_id == block.value.id && - this.blocks.push({ name: "  " + collection.value.name[0][0], value: collection.value.id, type: "collection" }); - }); - } - }); - }); + + /** + * 读取所有空间,并创建映射。 + */ + const spaceMaps = {} + Object.values(result.recordMap.space).forEach( + ({ value: spaceValue, role }) => { + if (!this.hasWriteRule(role)) return + spaceMaps[spaceValue.id] = { + name: spaceValue.name, + value: spaceValue.id, + type: 'space', + blocks: [], + } + } + ) + + /** + * 读取所有收藏空间,并创建映射。 + */ + const collectionMaps = {}; + Object.values( + result.recordMap.collection + ).forEach(({ value: collectionValue, role }) => { + if (!this.hasWriteRule(role)) return + collectionMaps[collectionValue.parent_id] = collectionValue + }) + + /** + * 遍历所有当前用户能看到的空间。 + */ + Object.values(result.recordMap.block).forEach( + ({ role, value: blockValue }) => { + if (!this.hasWriteRule(role)) return + const { + type, + space_id, + parent_id, + id, + } = blockValue + + const _space = space_id + ? spaceMaps[space_id] + : spaceMaps[parent_id] + const _spaceBlocks = _space ? _space.blocks : this.blocks + + if (type == 'page') { + _spaceBlocks.push({ + name: '  ' + this.getBlockName(blockValue.properties.title), + value: id, + type: 'page', + }) + } else if (type == 'collection_view_page') { + const collection = collectionMaps[id] + if (!collection) return + _spaceBlocks.push({ + name: '  ' + this.getBlockName(collection.name), + value: collection.id, + type: 'collection', + }) + } + } + ) + + Object.values(spaceMaps).forEach((space) => { + const { blocks, ...spaceAttr } = space + this.blocks.push(spaceAttr) + this.blocks.push(...blocks) + }) + this.type = this.blocks[0].type; this.folder_id = this.blocks[0].value; callback( result, undefined ); From ee17ffc79b0ce0868e5e95f87688c84219b48910 Mon Sep 17 00:00:00 2001 From: Dio Woo Date: Thu, 18 Jun 2020 14:17:06 +0800 Subject: [PATCH 05/30] =?UTF-8?q?*=20=E6=94=B6=E9=9B=86=E5=88=B0Table?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E5=A2=9E=E5=8A=A0URL=EF=BC=88=E9=99=90?= =?UTF-8?q?=E5=88=B6=EF=BC=9A=E6=8E=88=E6=9D=83=E5=90=8E=E9=80=89=E6=8B=A9?= =?UTF-8?q?block=E6=97=B6=EF=BC=8C=E5=BF=85=E9=A1=BB=E8=A6=81=20type=20=3D?= =?UTF-8?q?=20url=20&&=20name=20=3D=20URL=20=E7=9A=84=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 后续尝试优化成自动创建。 --- src/module/authorize.jsx | 8 +++- src/service/export.js | 101 +++++++++++++++++++++++++++++++++++---- 2 files changed, 97 insertions(+), 12 deletions(-) diff --git a/src/module/authorize.jsx b/src/module/authorize.jsx index b8b6bdc82..31b60c71a 100644 --- a/src/module/authorize.jsx +++ b/src/module/authorize.jsx @@ -287,9 +287,13 @@ export default class Auth extends React.Component { save( state, value ) { state == "pocket" && ( storage.secret.pocket.tags = value.trim() ); state == "linnk" && ( storage.secret.linnk.group_name = value.trim() ); - state == "notion" && ( storage.secret.notion.folder_id = value.trim() ); - state == "notion" && ( storage.secret.notion.type = this.state.notion.filter( item => item.value == value.trim() )[0].type ); state == "youdao" && ( storage.secret.youdao.folder_id = value.trim() ); + if (state == 'notion') { + const notionState = this.state.notion.filter( item => item.value == value.trim() )[0]; + storage.secret.notion.folder_id = value.trim() + storage.secret.notion.type = notionState.type + storage.secret.notion.url_schema_key = notionState.url_schema_key + } storage.Safe( () => this.setState({ secret: storage.secret }), storage.secret ); } diff --git a/src/service/export.js b/src/service/export.js index 95fd137a8..e0f4cb45c 100644 --- a/src/service/export.js +++ b/src/service/export.js @@ -1298,11 +1298,34 @@ class Notion { ).forEach(({ value: collectionValue, role }) => { if (!this.hasWriteRule(role)) return collectionMaps[collectionValue.parent_id] = collectionValue + collectionMaps[collectionValue.id] = collectionValue }) /** * 遍历所有当前用户能看到的空间。 */ + const processCollection = (id, spaceBlocks) => { + const collection = collectionMaps[id] + if (!collection) return + + let URLSchemaKey = null; + + Object.keys(collection.schema).some((key) => { + const schema = collection.schema[key] + if (schema.type === 'url' && schema.name === 'URL') { + URLSchemaKey = key; + return true + } + return false + }) + + spaceBlocks.push({ + name: '  ' + this.getBlockName(collection.name), + value: collection.id, + type: 'collection', + url_schema_key: URLSchemaKey, + }) + } Object.values(result.recordMap.block).forEach( ({ role, value: blockValue }) => { if (!this.hasWriteRule(role)) return @@ -1311,6 +1334,7 @@ class Notion { space_id, parent_id, id, + collection_id, } = blockValue const _space = space_id @@ -1319,22 +1343,22 @@ class Notion { const _spaceBlocks = _space ? _space.blocks : this.blocks if (type == 'page') { - _spaceBlocks.push({ - name: '  ' + this.getBlockName(blockValue.properties.title), + _spaceBlocks.push({ + name: + '  ' + + this.getBlockName(blockValue.properties.title), value: id, type: 'page', }) } else if (type == 'collection_view_page') { - const collection = collectionMaps[id] - if (!collection) return - _spaceBlocks.push({ - name: '  ' + this.getBlockName(collection.name), - value: collection.id, - type: 'collection', - }) + processCollection(id, _spaceBlocks) + } else if (type == 'collection_view') { + processCollection(collection_id, _spaceBlocks) } } ) + + Object.values(spaceMaps).forEach((space) => { const { blocks, ...spaceAttr } = space @@ -1524,7 +1548,64 @@ class Notion { }, } } - }), result => callback( result )); + }), result => { + if (this.type == 'collection' && this.url_schema_key) { + result.done && this.CheckQueueTask(result.done.data.taskId, () => { + this.SetProperties(documentId, () => callback(result)) + }) + } else { + callback(result) + } + }); + } + + CheckQueueTask(taskId, callback){ + if (taskId) { + browser.runtime.sendMessage( + msg.Add(msg.MESSAGE_ACTION.AXIOS, { + type: 'post', + url: this.url + 'api/v3/getTasks', + data: { + taskIds: [taskId], + }, + }), + (result) => { + if (result.done) { + const { results } = result.done.data + if (results[0].state !== 'success') { + setTimeout(() => { + this.CheckQueueTask(taskId, callback) + }, 500) + } else { + callback() + } + } + } + ) + } + } + + SetProperties(documentId, callback){ + browser.runtime.sendMessage( + msg.Add(msg.MESSAGE_ACTION.AXIOS, { + type: 'post', + url: this.url + 'api/v3/submitTransaction', + data: { + operations: [ + { + id: documentId, + table: 'block', + path: ['properties', this.url_schema_key], + command: 'set', + args: [[window.location.href, [['a', window.location.href]]]], + }, + ], + }, + }), + (result) => { + result.done && callback(documentId, undefined) + } + ) } } From 7b46536a50df22a546faf216905006d75d8cea21 Mon Sep 17 00:00:00 2001 From: Dio Woo Date: Thu, 18 Jun 2020 18:10:32 +0800 Subject: [PATCH 06/30] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=88=9B=E5=BB=BAURL=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/service/export.js | 110 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 105 insertions(+), 5 deletions(-) diff --git a/src/service/export.js b/src/service/export.js index e0f4cb45c..e13d0924f 100644 --- a/src/service/export.js +++ b/src/service/export.js @@ -11,6 +11,7 @@ import * as msg from 'message'; import {browser} from 'browser'; import * as puplugin from 'puplugin'; import * as wiz from 'wiz'; +import {storage} from 'storage' /** * Create PNG @@ -1549,16 +1550,115 @@ class Notion { } } }), result => { - if (this.type == 'collection' && this.url_schema_key) { - result.done && this.CheckQueueTask(result.done.data.taskId, () => { + if (this.type == 'collection') { + /* result.done && this.CheckQueueTask(result.done.data.taskId, () => { this.SetProperties(documentId, () => callback(result)) - }) + }) */ + const taskId = result.done.data.taskId; + if (result.done) { + this.CheckQueueTask(taskId, () => { + if (this.url_schema_key) { + this.SetProperties(documentId, () => callback(result)) + } else { + this.GetCollectionData((collection) => { + this.AddCollectionUrlSchema(collection, (schemaKey) => { + this.url_schema_key = schemaKey + storage.Safe(() => { + storage.secret.notion.url_schema_key = schemaKey + }) + this.SetProperties(documentId, () => callback(result)) + }) + }) + } + }) + } } else { callback(result) } }); } + GetCollectionData(callback){ + browser.runtime.sendMessage( + msg.Add(msg.MESSAGE_ACTION.AXIOS, { + type: 'post', + url: this.url + 'api/v3/loadUserContent', + }), + (result) => { + if (result.done) { + const { + recordMap: { collection }, + } = result.done.data + + const currentCollection = collection[this.folder_id].value; + callback(currentCollection) + } + } + ) + } + + AddCollectionUrlSchema(collection, callback){ + const { schema } = collection + const schemaKeys = Object.keys(schema); + let urlSchemaKey = null + schemaKeys.some((key) => { + const schemaItem = schema[key] + if (schemaItem.type === 'url' && schemaItem.name === 'URL') { + urlSchemaKey = key + return true + } + return false + }) + if (urlSchemaKey) { + callback(urlSchemaKey) + return; + } + + const newSchema = { ...schema } + let newSchemaKey = '' + while (!newSchemaKey && schemaKeys.indexOf(newSchemaKey) < 0) { + newSchemaKey = genSchemaKey() + } + + newSchema[newSchemaKey] = { + type: 'url', + name: 'URL', + } + + browser.runtime.sendMessage( + msg.Add(msg.MESSAGE_ACTION.AXIOS, { + type: 'post', + url: this.url + 'api/v3/submitTransaction', + data: { + operations: [ + { + args: { + schema: newSchema, + }, + command: 'update', + id: this.folder_id, + path: [], + table: 'collection', + }, + ], + }, + }), + (result) => { + if (result.done) { + callback(newSchemaKey) + } + } + ) + + function genSchemaKey(len = 4){ + let key = ''; + for (; key.length < len; ){ + key += String.fromCharCode(33 + 94 * Math.random()) + } + return key + } + } + CheckQueueTask(taskId, callback){ if (taskId) { browser.runtime.sendMessage( @@ -1575,7 +1675,7 @@ class Notion { if (results[0].state !== 'success') { setTimeout(() => { this.CheckQueueTask(taskId, callback) - }, 500) + }, 1000) } else { callback() } @@ -1597,7 +1697,7 @@ class Notion { table: 'block', path: ['properties', this.url_schema_key], command: 'set', - args: [[window.location.href, [['a', window.location.href]]]], + args: [[window.location.origin, [['a', window.location.href]]]], }, ], }, From fe05c00c16fc98004907fbc8ee3381962a0889b4 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Sat, 20 Jun 2020 12:36:00 +0800 Subject: [PATCH 07/30] Format source. --- src/service/export.js | 115 +++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 63 deletions(-) diff --git a/src/service/export.js b/src/service/export.js index e13d0924f..03425d880 100644 --- a/src/service/export.js +++ b/src/service/export.js @@ -1278,18 +1278,16 @@ class Notion { * 读取所有空间,并创建映射。 */ const spaceMaps = {} - Object.values(result.recordMap.space).forEach( - ({ value: spaceValue, role }) => { - if (!this.hasWriteRule(role)) return + Object.values( result.recordMap.space ).forEach(({ value: spaceValue, role }) => { + if (!this.hasWriteRule(role)) return; spaceMaps[spaceValue.id] = { - name: spaceValue.name, - value: spaceValue.id, - type: 'space', - blocks: [], + name : spaceValue.name, + value : spaceValue.id, + type : 'space', + blocks: [], } - } - ) - + }); + /** * 读取所有收藏空间,并创建映射。 */ @@ -1297,75 +1295,66 @@ class Notion { Object.values( result.recordMap.collection ).forEach(({ value: collectionValue, role }) => { - if (!this.hasWriteRule(role)) return - collectionMaps[collectionValue.parent_id] = collectionValue - collectionMaps[collectionValue.id] = collectionValue + if (!this.hasWriteRule(role)) return; + collectionMaps[ collectionValue.parent_id ] = collectionValue; + collectionMaps[ collectionValue.id ] = collectionValue; }) /** * 遍历所有当前用户能看到的空间。 */ - const processCollection = (id, spaceBlocks) => { - const collection = collectionMaps[id] - if (!collection) return - - let URLSchemaKey = null; - - Object.keys(collection.schema).some((key) => { - const schema = collection.schema[key] - if (schema.type === 'url' && schema.name === 'URL') { - URLSchemaKey = key; - return true - } - return false - }) - - spaceBlocks.push({ - name: '  ' + this.getBlockName(collection.name), - value: collection.id, - type: 'collection', - url_schema_key: URLSchemaKey, - }) + const processCollection = ( id, spaceBlocks ) => { + const collection = collectionMaps[id]; + if ( !collection ) return; + + let URLSchemaKey = null; + Object.keys(collection.schema).some( key => { + const schema = collection.schema[key] + if ( schema.type === 'url' && schema.name === 'URL' ) { + URLSchemaKey = key; + return true; + } + return false; + }) + + spaceBlocks.push({ + name : '  ' + this.getBlockName( collection.name ), + value: collection.id, + type : 'collection', + url_schema_key: URLSchemaKey, + }) } - Object.values(result.recordMap.block).forEach( - ({ role, value: blockValue }) => { - if (!this.hasWriteRule(role)) return + Object.values( result.recordMap.block ).forEach( ({ role, value: blockValue }) => { + if (!this.hasWriteRule(role)) return; const { type, space_id, parent_id, id, collection_id, - } = blockValue + } = blockValue; - const _space = space_id - ? spaceMaps[space_id] - : spaceMaps[parent_id] - const _spaceBlocks = _space ? _space.blocks : this.blocks + const _space = space_id ? spaceMaps[space_id] : spaceMaps[parent_id], + _spaceBlocks = _space ? _space.blocks : this.blocks; if (type == 'page') { - _spaceBlocks.push({ - name: - '  ' + - this.getBlockName(blockValue.properties.title), - value: id, - type: 'page', - }) - } else if (type == 'collection_view_page') { - processCollection(id, _spaceBlocks) - } else if (type == 'collection_view') { - processCollection(collection_id, _spaceBlocks) + _spaceBlocks.push({ + name : '  ' + this.getBlockName( blockValue.properties.title ), + value: id, + type : 'page', + }); + } else if ( type == 'collection_view_page' ) { + processCollection( id, _spaceBlocks ); + } else if ( type == 'collection_view' ) { + processCollection( collection_id, _spaceBlocks ); } - } - ) - - - - Object.values(spaceMaps).forEach((space) => { - const { blocks, ...spaceAttr } = space - this.blocks.push(spaceAttr) - this.blocks.push(...blocks) - }) + }); + + Object.values( spaceMaps ).forEach( space => { + const { blocks, ...spaceAttr } = space; + this.blocks.push( spaceAttr ); + this.blocks.push( ...blocks ); + }); this.type = this.blocks[0].type; this.folder_id = this.blocks[0].value; From 761b150fb40faaa584a6c1d61524a81188571ca1 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Sat, 20 Jun 2020 12:54:55 +0800 Subject: [PATCH 08/30] Optimize notion.blocks data structure. --- src/service/export.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/service/export.js b/src/service/export.js index 03425d880..c57dad0ca 100644 --- a/src/service/export.js +++ b/src/service/export.js @@ -1350,10 +1350,12 @@ class Notion { } }); - Object.values( spaceMaps ).forEach( space => { + Object.values( spaceMaps ).forEach( ( space, idx ) => { const { blocks, ...spaceAttr } = space; - this.blocks.push( spaceAttr ); - this.blocks.push( ...blocks ); + if ( blocks && blocks.length > 0 ) { + this.blocks.push({ name: spaceAttr.name, type: blocks[0].type, value: blocks[0].value, url_schema_key: blocks[0].url_schema_key }); + this.blocks.push( ...blocks ); + } }); this.type = this.blocks[0].type; From 723df2a1308aad0f100848844024a7958560ec49 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Sat, 20 Jun 2020 12:57:26 +0800 Subject: [PATCH 09/30] Format source. --- src/service/export.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service/export.js b/src/service/export.js index c57dad0ca..72f07f93b 100644 --- a/src/service/export.js +++ b/src/service/export.js @@ -1353,7 +1353,7 @@ class Notion { Object.values( spaceMaps ).forEach( ( space, idx ) => { const { blocks, ...spaceAttr } = space; if ( blocks && blocks.length > 0 ) { - this.blocks.push({ name: spaceAttr.name, type: blocks[0].type, value: blocks[0].value, url_schema_key: blocks[0].url_schema_key }); + this.blocks.push({ name: spaceAttr.name, type: blocks[0].type, value: blocks[0].value }); this.blocks.push( ...blocks ); } }); From 10ec636f542d62c1ea0cb0339b6173e20f37d501 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Sat, 20 Jun 2020 13:20:56 +0800 Subject: [PATCH 10/30] Format source. --- src/service/export.js | 239 ++++++++++++++++++++---------------------- 1 file changed, 112 insertions(+), 127 deletions(-) diff --git a/src/service/export.js b/src/service/export.js index 72f07f93b..fc84df5c8 100644 --- a/src/service/export.js +++ b/src/service/export.js @@ -1350,7 +1350,7 @@ class Notion { } }); - Object.values( spaceMaps ).forEach( ( space, idx ) => { + Object.values( spaceMaps ).forEach( space => { const { blocks, ...spaceAttr } = space; if ( blocks && blocks.length > 0 ) { this.blocks.push({ name: spaceAttr.name, type: blocks[0].type, value: blocks[0].value }); @@ -1541,161 +1541,146 @@ class Notion { } } }), result => { - if (this.type == 'collection') { + if ( this.type == 'collection' ) { /* result.done && this.CheckQueueTask(result.done.data.taskId, () => { this.SetProperties(documentId, () => callback(result)) }) */ const taskId = result.done.data.taskId; - if (result.done) { - this.CheckQueueTask(taskId, () => { - if (this.url_schema_key) { - this.SetProperties(documentId, () => callback(result)) - } else { - this.GetCollectionData((collection) => { - this.AddCollectionUrlSchema(collection, (schemaKey) => { - this.url_schema_key = schemaKey - storage.Safe(() => { - storage.secret.notion.url_schema_key = schemaKey - }) - this.SetProperties(documentId, () => callback(result)) - }) - }) - } - }) - } - } else { - callback(result) - } + if ( result.done ) { + this.CheckQueueTask( taskId, () => { + if ( this.url_schema_key ) { + this.SetProperties( documentId, () => callback( result )); + } else { + this.GetCollectionData( collection => { + this.AddCollectionUrlSchema( collection, schemaKey => { + this.url_schema_key = schemaKey; + storage.Safe(() => { + storage.secret.notion.url_schema_key = schemaKey; + }); + this.SetProperties( documentId, () => callback( result )); + }); + }); + } + }) + } + } else callback( result ); }); } - GetCollectionData(callback){ + GetCollectionData( callback ) { browser.runtime.sendMessage( - msg.Add(msg.MESSAGE_ACTION.AXIOS, { - type: 'post', - url: this.url + 'api/v3/loadUserContent', - }), - (result) => { - if (result.done) { - const { - recordMap: { collection }, - } = result.done.data - - const currentCollection = collection[this.folder_id].value; - callback(currentCollection) + msg.Add( msg.MESSAGE_ACTION.AXIOS, { + type: 'post', + url : this.url + 'api/v3/loadUserContent', + }), result => { + if (result.done) { + const { + recordMap: { collection }, + } = result.done.data, + currentCollection = collection[ this.folder_id ].value; + callback( currentCollection ); + } } - } ) } - AddCollectionUrlSchema(collection, callback){ - const { schema } = collection - const schemaKeys = Object.keys(schema); - let urlSchemaKey = null - schemaKeys.some((key) => { - const schemaItem = schema[key] - if (schemaItem.type === 'url' && schemaItem.name === 'URL') { - urlSchemaKey = key - return true - } - return false - }) - if (urlSchemaKey) { - callback(urlSchemaKey) - return; - } + AddCollectionUrlSchema( collection, callback ) { + const { schema } = collection, + schemaKeys = Object.keys( schema ), + genSchemaKey = ( len = 4 ) => { + let key = ''; + for ( ; key.length < len; ) { + key += String.fromCharCode( 33 + 94 * Math.random()); + } + return key; + }; + let urlSchemaKey = null; + + schemaKeys.some( key => { + const schemaItem = schema[key]; + if ( schemaItem.type === 'url' && schemaItem.name === 'URL' ) { + urlSchemaKey = key; + return true; + } + return false; + }); - const newSchema = { ...schema } - let newSchemaKey = '' - while (!newSchemaKey && schemaKeys.indexOf(newSchemaKey) < 0) { - newSchemaKey = genSchemaKey() + if ( urlSchemaKey ) { + callback( urlSchemaKey ); + return; } - newSchema[newSchemaKey] = { - type: 'url', - name: 'URL', + const newSchema = { ...schema }; + let newSchemaKey = ''; + while ( !newSchemaKey && schemaKeys.indexOf(newSchemaKey) < 0 ) { + newSchemaKey = genSchemaKey(); } + newSchema[ newSchemaKey ] = { type: 'url', name: 'URL' }; + browser.runtime.sendMessage( - msg.Add(msg.MESSAGE_ACTION.AXIOS, { - type: 'post', - url: this.url + 'api/v3/submitTransaction', - data: { - operations: [ - { - args: { - schema: newSchema, - }, - command: 'update', - id: this.folder_id, - path: [], - table: 'collection', + msg.Add( msg.MESSAGE_ACTION.AXIOS, { + type: 'post', + url : this.url + 'api/v3/submitTransaction', + data: { + operations: [{ + args: { + schema: newSchema, + }, + command: 'update', + id: this.folder_id, + path: [], + table: 'collection', + }], }, - ], - }, - }), - (result) => { - if (result.done) { - callback(newSchemaKey) + }), result => { + if ( result.done ) { + callback( newSchemaKey ); + } } - } ) - - function genSchemaKey(len = 4){ - let key = ''; - for (; key.length < len; ){ - key += String.fromCharCode(33 + 94 * Math.random()) - } - return key - } } - CheckQueueTask(taskId, callback){ - if (taskId) { - browser.runtime.sendMessage( - msg.Add(msg.MESSAGE_ACTION.AXIOS, { - type: 'post', - url: this.url + 'api/v3/getTasks', - data: { - taskIds: [taskId], - }, - }), - (result) => { - if (result.done) { - const { results } = result.done.data - if (results[0].state !== 'success') { - setTimeout(() => { - this.CheckQueueTask(taskId, callback) - }, 1000) - } else { - callback() + CheckQueueTask( taskId, callback ) { + if ( taskId ) { + browser.runtime.sendMessage( + msg.Add(msg.MESSAGE_ACTION.AXIOS, { + type: 'post', + url : this.url + 'api/v3/getTasks', + data: { + taskIds: [taskId], + }, + }), result => { + if ( result.done ) { + const { results } = result.done.data; + if ( results[0].state !== 'success' ) { + setTimeout( () => { + this.CheckQueueTask( taskId, callback ); + }, 1000 ); + } else callback(); + } } - } - } - ) + ) } } - SetProperties(documentId, callback){ + SetProperties( documentId, callback ) { browser.runtime.sendMessage( - msg.Add(msg.MESSAGE_ACTION.AXIOS, { - type: 'post', - url: this.url + 'api/v3/submitTransaction', - data: { - operations: [ - { - id: documentId, - table: 'block', - path: ['properties', this.url_schema_key], - command: 'set', - args: [[window.location.origin, [['a', window.location.href]]]], + msg.Add( msg.MESSAGE_ACTION.AXIOS, { + type: 'post', + url: this.url + 'api/v3/submitTransaction', + data: { + operations: [{ + id: documentId, + table: 'block', + path: ['properties', this.url_schema_key], + command: 'set', + args: [[ window.location.origin, [[ 'a', window.location.href ]]]], + }], }, - ], - }, - }), - (result) => { - result.done && callback(documentId, undefined) - } + }), result => { + result.done && callback( documentId, undefined ); + } ) } From c43a50ee30ea63bf696b30793700f4b3d17142ff Mon Sep 17 00:00:00 2001 From: Kenshin Date: Sat, 20 Jun 2020 13:21:21 +0800 Subject: [PATCH 11/30] Format source. --- src/service/export.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service/export.js b/src/service/export.js index fc84df5c8..a578f4140 100644 --- a/src/service/export.js +++ b/src/service/export.js @@ -1668,7 +1668,7 @@ class Notion { browser.runtime.sendMessage( msg.Add( msg.MESSAGE_ACTION.AXIOS, { type: 'post', - url: this.url + 'api/v3/submitTransaction', + url : this.url + 'api/v3/submitTransaction', data: { operations: [{ id: documentId, From 73ea1f2b81f48761eb13bccb4e9ff455061c981e Mon Sep 17 00:00:00 2001 From: Kenshin Date: Sat, 20 Jun 2020 14:54:23 +0800 Subject: [PATCH 12/30] Change 'url_schema_key' to 'schema' and add notion.schema logic. --- src/module/authorize.jsx | 6 +++--- src/service/export.js | 10 +++++----- src/service/output.js | 1 + 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/module/authorize.jsx b/src/module/authorize.jsx index 31b60c71a..24d6415b5 100644 --- a/src/module/authorize.jsx +++ b/src/module/authorize.jsx @@ -290,9 +290,9 @@ export default class Auth extends React.Component { state == "youdao" && ( storage.secret.youdao.folder_id = value.trim() ); if (state == 'notion') { const notionState = this.state.notion.filter( item => item.value == value.trim() )[0]; - storage.secret.notion.folder_id = value.trim() - storage.secret.notion.type = notionState.type - storage.secret.notion.url_schema_key = notionState.url_schema_key + storage.secret.notion.folder_id = value.trim(); + storage.secret.notion.type = notionState.type; + storage.secret.notion.schema = notionState.schema; } storage.Safe( () => this.setState({ secret: storage.secret }), storage.secret ); } diff --git a/src/service/export.js b/src/service/export.js index a578f4140..6f7896b1f 100644 --- a/src/service/export.js +++ b/src/service/export.js @@ -1321,7 +1321,7 @@ class Notion { name : '  ' + this.getBlockName( collection.name ), value: collection.id, type : 'collection', - url_schema_key: URLSchemaKey, + schema: URLSchemaKey, }) } Object.values( result.recordMap.block ).forEach( ({ role, value: blockValue }) => { @@ -1548,14 +1548,14 @@ class Notion { const taskId = result.done.data.taskId; if ( result.done ) { this.CheckQueueTask( taskId, () => { - if ( this.url_schema_key ) { + if ( this.schema ) { this.SetProperties( documentId, () => callback( result )); } else { this.GetCollectionData( collection => { this.AddCollectionUrlSchema( collection, schemaKey => { - this.url_schema_key = schemaKey; + this.schema = schemaKey; storage.Safe(() => { - storage.secret.notion.url_schema_key = schemaKey; + storage.secret.notion.schema = schemaKey; }); this.SetProperties( documentId, () => callback( result )); }); @@ -1673,7 +1673,7 @@ class Notion { operations: [{ id: documentId, table: 'block', - path: ['properties', this.url_schema_key], + path: ['properties', this.schema], command: 'set', args: [[ window.location.origin, [[ 'a', window.location.href ]]]], }], diff --git a/src/service/output.js b/src/service/output.js index 80d104d20..28e118b0c 100644 --- a/src/service/output.js +++ b/src/service/output.js @@ -316,6 +316,7 @@ function action( type, title, desc, content ) { corbLoader( "load", () => { notion.access_token = storage.secret.notion.access_token; notion.folder_id = storage.secret.notion.folder_id; + notion.schema = storage.secret.notion.schema; notion.Add( title, result.replace( /.jpeg!720/ig, '.jpeg' ), ( result, error ) => { exp.svcCbWrapper( result, error, notion.name, type, new Notify() ) }); From 10bf98832b633842a4b0ab527f0681cb32193661 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Sat, 20 Jun 2020 14:55:12 +0800 Subject: [PATCH 13/30] Format source. --- 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 24d6415b5..5715189ee 100644 --- a/src/module/authorize.jsx +++ b/src/module/authorize.jsx @@ -289,10 +289,10 @@ export default class Auth extends React.Component { state == "linnk" && ( storage.secret.linnk.group_name = value.trim() ); state == "youdao" && ( storage.secret.youdao.folder_id = value.trim() ); if (state == 'notion') { - const notionState = this.state.notion.filter( item => item.value == value.trim() )[0]; + const obj = this.state.notion.filter( item => item.value == value.trim() )[0]; storage.secret.notion.folder_id = value.trim(); - storage.secret.notion.type = notionState.type; - storage.secret.notion.schema = notionState.schema; + storage.secret.notion.type = obj.type; + storage.secret.notion.schema = obj.schema; } storage.Safe( () => this.setState({ secret: storage.secret }), storage.secret ); } From 97961700622d0071016ed3608d70778176ceded3 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Sat, 20 Jun 2020 15:00:57 +0800 Subject: [PATCH 14/30] Format source. --- src/service/export.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/service/export.js b/src/service/export.js index 6f7896b1f..eedf1cb58 100644 --- a/src/service/export.js +++ b/src/service/export.js @@ -1307,21 +1307,21 @@ class Notion { const collection = collectionMaps[id]; if ( !collection ) return; - let URLSchemaKey = null; - Object.keys(collection.schema).some( key => { - const schema = collection.schema[key] + let schemaKey = null; + Object.keys( collection.schema ).some( key => { + const schema = collection.schema[key]; if ( schema.type === 'url' && schema.name === 'URL' ) { - URLSchemaKey = key; + schemaKey = key; return true; } return false; }) spaceBlocks.push({ - name : '  ' + this.getBlockName( collection.name ), - value: collection.id, - type : 'collection', - schema: URLSchemaKey, + name : '  ' + this.getBlockName( collection.name ), + value : collection.id, + type : 'collection', + schema: schemaKey, }) } Object.values( result.recordMap.block ).forEach( ({ role, value: blockValue }) => { @@ -1594,19 +1594,19 @@ class Notion { } return key; }; - let urlSchemaKey = null; + let schemaKey = null; schemaKeys.some( key => { const schemaItem = schema[key]; if ( schemaItem.type === 'url' && schemaItem.name === 'URL' ) { - urlSchemaKey = key; + schemaKey = key; return true; } return false; }); - if ( urlSchemaKey ) { - callback( urlSchemaKey ); + if ( schemaKey ) { + callback( schemaKey ); return; } From 5b7a7537746a566fe7c85c35133b44e04fa092d5 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Sat, 20 Jun 2020 15:34:32 +0800 Subject: [PATCH 15/30] Optimize notion.schema workflow. --- src/module/authorize.jsx | 10 +++++----- src/service/export.js | 9 +++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/module/authorize.jsx b/src/module/authorize.jsx index 5715189ee..6d4af2f8c 100644 --- a/src/module/authorize.jsx +++ b/src/module/authorize.jsx @@ -288,11 +288,11 @@ export default class Auth extends React.Component { state == "pocket" && ( storage.secret.pocket.tags = value.trim() ); state == "linnk" && ( storage.secret.linnk.group_name = value.trim() ); state == "youdao" && ( storage.secret.youdao.folder_id = value.trim() ); - if (state == 'notion') { - const obj = this.state.notion.filter( item => item.value == value.trim() )[0]; - storage.secret.notion.folder_id = value.trim(); - storage.secret.notion.type = obj.type; - storage.secret.notion.schema = obj.schema; + if ( state == 'notion' ) { + const obj = this.state.notion.filter( item => item.value == value.trim() )[0]; + storage.secret.notion.folder_id = value.trim(); + storage.secret.notion.type = obj.type; + obj.schema && ( storage.secret.notion.schema = obj.schema ); } storage.Safe( () => this.setState({ secret: storage.secret }), storage.secret ); } diff --git a/src/service/export.js b/src/service/export.js index eedf1cb58..95034a0da 100644 --- a/src/service/export.js +++ b/src/service/export.js @@ -1307,7 +1307,7 @@ class Notion { const collection = collectionMaps[id]; if ( !collection ) return; - let schemaKey = null; + let schemaKey; Object.keys( collection.schema ).some( key => { const schema = collection.schema[key]; if ( schema.type === 'url' && schema.name === 'URL' ) { @@ -1317,12 +1317,13 @@ class Notion { return false; }) - spaceBlocks.push({ + const block = { name : '  ' + this.getBlockName( collection.name ), value : collection.id, type : 'collection', - schema: schemaKey, - }) + }; + schemaKey && ( block.schema = schemaKey ); + spaceBlocks.push( block ); } Object.values( result.recordMap.block ).forEach( ({ role, value: blockValue }) => { if (!this.hasWriteRule(role)) return; From 443dbc50dfc00e0be5659e2dce23f07aa5fb2c00 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Sat, 20 Jun 2020 15:34:43 +0800 Subject: [PATCH 16/30] Format source. --- src/service/export.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/service/export.js b/src/service/export.js index 95034a0da..6e5f9293b 100644 --- a/src/service/export.js +++ b/src/service/export.js @@ -1328,11 +1328,11 @@ class Notion { Object.values( result.recordMap.block ).forEach( ({ role, value: blockValue }) => { if (!this.hasWriteRule(role)) return; const { - type, - space_id, - parent_id, - id, - collection_id, + type, + space_id, + parent_id, + id, + collection_id, } = blockValue; const _space = space_id ? spaceMaps[space_id] : spaceMaps[parent_id], From 9590e129d38aa1b467750d5ea5d11eeb457119bc Mon Sep 17 00:00:00 2001 From: Kenshin Date: Sat, 20 Jun 2020 15:34:55 +0800 Subject: [PATCH 17/30] Format source. --- src/service/export.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service/export.js b/src/service/export.js index 6e5f9293b..018945352 100644 --- a/src/service/export.js +++ b/src/service/export.js @@ -1326,7 +1326,7 @@ class Notion { spaceBlocks.push( block ); } Object.values( result.recordMap.block ).forEach( ({ role, value: blockValue }) => { - if (!this.hasWriteRule(role)) return; + if ( !this.hasWriteRule( role )) return; const { type, space_id, From f3c3bdfe7225c334d8359fcd70e74be148e25ada Mon Sep 17 00:00:00 2001 From: Kenshin Date: Sat, 20 Jun 2020 15:59:06 +0800 Subject: [PATCH 18/30] Optimize notion.type == collection && notion.schema set and save workflow. --- src/module/authorize.jsx | 1 + src/service/export.js | 10 ++++++---- src/service/output.js | 6 ++++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/module/authorize.jsx b/src/module/authorize.jsx index 6d4af2f8c..f317ca721 100644 --- a/src/module/authorize.jsx +++ b/src/module/authorize.jsx @@ -293,6 +293,7 @@ export default class Auth extends React.Component { storage.secret.notion.folder_id = value.trim(); storage.secret.notion.type = obj.type; obj.schema && ( storage.secret.notion.schema = obj.schema ); + obj.type == "page" && delete storage.secret.notion.schema; } storage.Safe( () => this.setState({ secret: storage.secret }), storage.secret ); } diff --git a/src/service/export.js b/src/service/export.js index 018945352..8092d3856 100644 --- a/src/service/export.js +++ b/src/service/export.js @@ -11,7 +11,6 @@ import * as msg from 'message'; import {browser} from 'browser'; import * as puplugin from 'puplugin'; import * as wiz from 'wiz'; -import {storage} from 'storage' /** * Create PNG @@ -1555,9 +1554,6 @@ class Notion { this.GetCollectionData( collection => { this.AddCollectionUrlSchema( collection, schemaKey => { this.schema = schemaKey; - storage.Safe(() => { - storage.secret.notion.schema = schemaKey; - }); this.SetProperties( documentId, () => callback( result )); }); }); @@ -1685,6 +1681,12 @@ class Notion { ) } + Save( storage ) { + storage.Safe( () => { + // TO-DO + }, storage.secret ); + } + } /** diff --git a/src/service/output.js b/src/service/output.js index 28e118b0c..5f57707cc 100644 --- a/src/service/output.js +++ b/src/service/output.js @@ -317,7 +317,13 @@ function action( type, title, desc, content ) { notion.access_token = storage.secret.notion.access_token; notion.folder_id = storage.secret.notion.folder_id; notion.schema = storage.secret.notion.schema; + notion.type = storage.secret.notion.type; notion.Add( title, result.replace( /.jpeg!720/ig, '.jpeg' ), ( result, error ) => { + // hack code + if ( notion.type == "collection" && notion.schema != storage.secret.notion.schema ) { + storage.secret.notion.schema = notion.schema; + notion.Save( storage ); + } exp.svcCbWrapper( result, error, notion.name, type, new Notify() ) }); }, 500 ); From 554b8bd0ce5b31a542b5d1024fbb233cd1704a64 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Sun, 21 Jun 2020 15:22:23 +0800 Subject: [PATCH 19/30] Add notify.update() and update version 2.0.2.0621. --- src/vender/notify/notify.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vender/notify/notify.js b/src/vender/notify/notify.js index 867810e8e..e7e62e4af 100644 --- a/src/vender/notify/notify.js +++ b/src/vender/notify/notify.js @@ -58,7 +58,7 @@ * */ var Notify = ( function () { - var VERSION = "2.0.2.0105", + var VERSION = "2.0.2.0621", name = "notify", root = "notify-gp", roottmpl= "<" + root + ">", @@ -184,7 +184,7 @@ var Notify = ( function () { this.title ? $title.text( this.title ) : $title.hide(); this.content ? $content.html( this.content ) : $content.hide(); - this.updateContent = function(content){ + this.update = function( content ) { this.content = content; this.content ? $content.html( this.content ) : $content.hide(); } From cc9c0c726f77e852a99b9759bcfa3555fcf21688 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Sun, 21 Jun 2020 15:25:31 +0800 Subject: [PATCH 20/30] Format source. --- src/service/export.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service/export.js b/src/service/export.js index 34614b3fe..857e4efb4 100644 --- a/src/service/export.js +++ b/src/service/export.js @@ -1446,7 +1446,7 @@ class Notion { const UploadOriginImage = this.UploadOriginImage.bind(this); const notify = new Notify().Render({ state: "loading", content: `正在采集图片到 Notion,请稍等` }); const updateNotify = function(){ - notify.updateContent(`正在采集图片到 Notion,请稍等 (${completeCount}/${imagesCount}) `) + notify.update( `正在采集图片到 Notion,请稍等 (${ completeCount }/${ imagesCount })` ); } replacements.push( await images.reduce((prevPromise, imageUrl) => { From 2b92a121381c2f14f5df74c9ba957f4a5674b928 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Sun, 21 Jun 2020 15:47:12 +0800 Subject: [PATCH 21/30] Optimize notion.save_image option page workflow. --- src/module/authorize.jsx | 12 +++++++----- src/service/output.js | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/module/authorize.jsx b/src/module/authorize.jsx index 54fdb0848..15480608a 100644 --- a/src/module/authorize.jsx +++ b/src/module/authorize.jsx @@ -524,17 +524,19 @@ export default class Auth extends React.Component { onChange={ (s)=>this.onChange( "notion", s ) } /> { this.state.secret.notion.access_token && -
+
{ this.state.notion ? this.save( "notion", v ) } /> :
} - { this.state.secret.notion.access_token && -
- this.save( "notion_save_image", v ) } checked={ this.state.secret.notion.save_image} label="将图片保存到Notion.so (速度较慢,慎重)"> + + this.save( "notion_save_image", s ) } />
}
diff --git a/src/service/output.js b/src/service/output.js index ca1719794..853f41006 100644 --- a/src/service/output.js +++ b/src/service/output.js @@ -316,7 +316,7 @@ function action( type, title, desc, content ) { corbLoader( "load", () => { notion.access_token = storage.secret.notion.access_token; notion.folder_id = storage.secret.notion.folder_id; - notion.save_image = storage.secret.notion.save_image; + notion.save_image = storage.secret.notion.save_image; notion.schema = storage.secret.notion.schema; notion.type = storage.secret.notion.type; notion.Add( title, result.replace( /.jpeg!720/ig, '.jpeg' ), ( result, error ) => { From a059a677a2b4e76c44e322d39d23ac8d9cea8d2a Mon Sep 17 00:00:00 2001 From: Dio Woo Date: Sun, 21 Jun 2020 16:33:07 +0800 Subject: [PATCH 22/30] =?UTF-8?q?fixed:=20=E5=BD=93=E9=93=BE=E6=8E=A5?= =?UTF-8?q?=E6=98=AFhttps=20=E4=BD=86=E8=B5=84=E6=BA=90=E5=BC=95=E7=94=A8?= =?UTF-8?q?=E6=98=AFhttp=20=E6=97=B6=E5=AF=BC=E8=87=B4=E7=9A=84replace?= =?UTF-8?q?=E5=8E=9F=E6=96=87=E7=9A=84=E5=9B=BE=E7=89=87=E9=93=BE=E6=8E=A5?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/options/corb.js | 4 ++-- src/service/export.js | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/options/corb.js b/src/options/corb.js index 74269bff0..7f531aa8f 100644 --- a/src/options/corb.js +++ b/src/options/corb.js @@ -44,10 +44,10 @@ browser.runtime.onMessage.addListener( function( request, sender, sendResponse ) if (request.type == msg.MESSAGE_ACTION.NOTION_DL_IMG) { try { const option = request.value - const { url } = option + const { url, protocol } = option const dlRes = await axios({ method: 'get', - url, + url: url.replace(/https?:/, protocol), responseType: 'blob', }) diff --git a/src/service/export.js b/src/service/export.js index 34614b3fe..5f7fac465 100644 --- a/src/service/export.js +++ b/src/service/export.js @@ -1390,7 +1390,8 @@ class Notion { return new Promise((resolve, reject) => { browser.runtime.sendMessage( msg.Add(msg.MESSAGE_ACTION.NOTION_DL_IMG, { - url:url.replace(/https?:/, window.location.protocol), + url, + protocol: window.location.protocol }), (res) => { if (res.done) { From d13a9358d1b038f1bb23fc5a77c7971e7b58bd13 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Sun, 21 Jun 2020 18:24:32 +0800 Subject: [PATCH 23/30] Format source. --- src/options/corb.js | 96 ++++++++++++++++++------------------------ src/service/message.js | 4 +- 2 files changed, 44 insertions(+), 56 deletions(-) diff --git a/src/options/corb.js b/src/options/corb.js index 74269bff0..6affcace3 100644 --- a/src/options/corb.js +++ b/src/options/corb.js @@ -21,10 +21,10 @@ browser.runtime.onMessage.addListener( function( request, sender, sendResponse ) axios.put( request.value.url, request.value.content, request.value.data ) .then( response => sendResponse({ done: response })) .catch( error => sendResponse({ fail: error })); - }else if( request.value.type == 'download' ) { - axios(request.value) - .then( response => sendResponse({ done: response })) - .catch( error => sendResponse({ fail: error })); + } else if( request.value.type == 'download' ) { + axios( request.value ) + .then( response => sendResponse({ done: response })) + .catch( error => sendResponse({ fail: error })); } } return true; @@ -33,59 +33,47 @@ browser.runtime.onMessage.addListener( function( request, sender, sendResponse ) /** * Listen runtime message, include: `notion` */ -;(function () { - const DownLoadCache = new Map(); +const downLoadCache = new Map(); - browser.runtime.onMessage.addListener(async function ( - request, - sender, - sendResponse - ) { - if (request.type == msg.MESSAGE_ACTION.NOTION_DL_IMG) { - try { - const option = request.value - const { url } = option - const dlRes = await axios({ - method: 'get', - url, - responseType: 'blob', - }) +browser.runtime.onMessage.addListener( async function ( request, sender, sendResponse ) { + if ( request.type == msg.MESSAGE_ACTION.NOTION_DL_IMG ) { + try { + const option = request.value, + { url } = option, + dlRes = await axios({ method: 'get', url, responseType: 'blob', }); + let blob = dlRes.data; - let blob = dlRes.data - - if (blob.type === 'image/webp') { - blob = blob.slice(0, blob.size, 'image/jpeg') + if ( blob.type === 'image/webp' ) { + blob = blob.slice( 0, blob.size, 'image/jpeg' ); + } + downLoadCache.set( url, blob ); + sendResponse({ + done: { + type: blob.type, + size: blob.size, + url, + }, + }); + } catch ( err ) { + sendResponse({ fail: err }); } - DownLoadCache.set(url, blob) - sendResponse({ - done: { - type: blob.type, - size: blob.size, - url, - }, - }) - } catch (err) { - sendResponse({ fail: err }) - } - } else if (request.type == msg.MESSAGE_ACTION.NOTION_UP_IMG) { - try { - const option = request.value - const { url, upUrl } = option + } else if ( request.type == msg.MESSAGE_ACTION.NOTION_UP_IMG ) { + try { + const option = request.value, + { url, upUrl } = option, + blob = downLoadCache.get( url ); - const blob = DownLoadCache.get(url) + await axios.put( upUrl, blob, { + headers: { + 'Content-Type': blob.type, + }, + }); - await axios.put(upUrl, blob, { - headers: { - 'Content-Type': blob.type, - }, - }) - - DownLoadCache.delete(url) - sendResponse({ done: true }) - } catch (err) { - sendResponse({ fail: err }) - } + downLoadCache.delete( url ); + sendResponse({ done: true }); + } catch ( err ) { + sendResponse({ fail: err }); + } } - return true - }) -})() + return true; +}); \ No newline at end of file diff --git a/src/service/message.js b/src/service/message.js index 9ca6108b9..54166e404 100644 --- a/src/service/message.js +++ b/src/service/message.js @@ -54,8 +54,8 @@ const action = { tips : "tips", tips_norepeat : "tips_norepeat", // notion.so - NOTION_DL_IMG : "notion_dl_img", - NOTION_UP_IMG : "notion_up_img", + NOTION_DL_IMG : "notion_dl_img", + NOTION_UP_IMG : "notion_up_img", }; /** From babc4dc26f10b06d6c19297d10eb24357eea4420 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Sun, 21 Jun 2020 18:49:09 +0800 Subject: [PATCH 24/30] Merge 'a059a67' source. --- src/options/corb.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/options/corb.js b/src/options/corb.js index 8d3800ce4..5bec9b9bd 100644 --- a/src/options/corb.js +++ b/src/options/corb.js @@ -40,7 +40,7 @@ browser.runtime.onMessage.addListener( async function ( request, sender, sendRes try { const option = request.value, { url, protocol } = option, - dlRes = await axios({ method: 'get', url, responseType: 'blob', }); + dlRes = await axios({ method: 'get', url: url.replace( /https?:/, protocol ), responseType: 'blob', }); let blob = dlRes.data; if ( blob.type === 'image/webp' ) { @@ -51,7 +51,7 @@ browser.runtime.onMessage.addListener( async function ( request, sender, sendRes done: { type: blob.type, size: blob.size, - url : url.replace( /https?:/, protocol ), + url, }, }); } catch ( err ) { From 48ceb5b04bf5ac314a2285d7a455f43c98b81a37 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Mon, 22 Jun 2020 11:23:24 +0800 Subject: [PATCH 25/30] Format source. --- src/service/export.js | 162 +++++++++++++++++++----------------------- 1 file changed, 73 insertions(+), 89 deletions(-) diff --git a/src/service/export.js b/src/service/export.js index 1a66de640..c1cd383e7 100644 --- a/src/service/export.js +++ b/src/service/export.js @@ -1369,114 +1369,98 @@ class Notion { } MathImages( content ) { - const result = content.match(/!\[.*?\]\(http(.*?)\)/g) + const result = content.match( /!\[.*?\]\(http(.*?)\)/g ); - if( !result ){ return [] } + if( !result ) { return []; } - const images = result - .map(o => { - const temp = /!\[.*?\]\((http.*?)\)/.exec(o); - if (temp) { - return temp[1]; + const images = result.map( o => { + const temp = /!\[.*?\]\((http.*?)\)/.exec( o ); + if ( temp ) { + return temp[1]; } return ''; - }) - .filter(o => o && !~o.indexOf('secure.notion-static.com/')); - - return images + }).filter( o => o && !~o.indexOf( 'secure.notion-static.com/' )); + return images; } - DonwloadOriginImage(url) { - return new Promise((resolve, reject) => { + DonwloadOriginImage( url ) { + return new Promise(( resolve, reject ) => { browser.runtime.sendMessage( - msg.Add(msg.MESSAGE_ACTION.NOTION_DL_IMG, { + msg.Add( msg.MESSAGE_ACTION.NOTION_DL_IMG, { url, protocol: window.location.protocol - }), - (res) => { - if (res.done) { - resolve(res.done) - } else { - reject(res.fail) - } - } - ) - }) + }), res => { + if ( res.done ) resolve( res.done ); + else reject( res.fail ); + }); + }); } - UploadOriginImage ( { type, size, url } ){ - return new Promise((resolve, reject) => { - this.GetFileUrl( - this.UUID(), - (urls) => { - browser.runtime.sendMessage( - msg.Add(msg.MESSAGE_ACTION.NOTION_UP_IMG, { - url: url, - upUrl: urls.signedPutUrl, - }), - (res) => { - if (res.done) { - resolve({ - from: url, - to: urls.url, - }) - } else { - resolve() - } + UploadOriginImage({ type, size, url }) { + return new Promise(( resolve, reject ) => { + this.GetFileUrl( + this.UUID(), + urls => { + browser.runtime.sendMessage( + msg.Add( msg.MESSAGE_ACTION.NOTION_UP_IMG, { + url: url, + upUrl: urls.signedPutUrl, + }), res => { + if ( res.done ) { + resolve({ from: url, to: urls.url }); + } else resolve(); + } + ) + }, + { + bucket: 'secure', + contentType: type, } - ) - }, - { - bucket: 'secure', - contentType: type, - } - ) + ) }) } - async UploadImages ( content ) { + async UploadImages( content ) { - function escapeRegExp(string) { - return string.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&') // $& means the whole matched string - } - - const images = [...new Set(this.MathImages(content))] - const imagesCount = images.length; - let completeCount = 0; - const replacements = [] - const UploadOriginImage = this.UploadOriginImage.bind(this); - const notify = new Notify().Render({ state: "loading", content: `正在采集图片到 Notion,请稍等` }); - const updateNotify = function(){ - notify.update( `正在采集图片到 Notion,请稍等 (${ completeCount }/${ imagesCount })` ); - } + let completeCount = 0; + const images = [ ...new Set( this.MathImages( content ))], + imagesCount = images.length, + replacements = [], + uploadImage = this.UploadOriginImage.bind( this ), + notify = new Notify().Render({ state: "loading", content: `正在上传图片到 Notion ,请稍等` }), + updateNotify = () => { + notify.update( `正在上传图片到 Notion ,当前进度 ${ completeCount }/${ imagesCount }` ); + }, + escapeRegExp = str => { + return str.replace( /[.*+\-?^${}()|[\]\\]/g, '\\$&' ); // $& means the whole matched string + }; replacements.push( - await images.reduce((prevPromise, imageUrl) => { - if (!imageUrl) return - console.log(' Notion Download Image :' + imageUrl) - return prevPromise.then((replacement) => { - if (replacement) { - replacements.push(replacement) - } - completeCount ++; - updateNotify() - return this.DonwloadOriginImage(imageUrl).then( - UploadOriginImage, - (err) => { - console.error(err) - } - ) - }) - }, Promise.resolve()) + await images.reduce(( prevPromise, imageUrl ) => { + if ( !imageUrl ) return; + return prevPromise.then(( replacement ) => { + if ( replacement ) { + replacements.push( replacement ); + } + completeCount ++; + updateNotify(); + return this.DonwloadOriginImage( imageUrl ).then( + uploadImage, + err => { + console.error(err) + } + ) + }); + }, Promise.resolve()) ) notify.complete(); - replacements.forEach((replacement) => { - if (replacement) { - content = content.replace( - new RegExp(escapeRegExp(replacement.from),'g'), - replacement.to - ) - } + replacements.forEach(( replacement ) => { + if ( replacement ) { + content = content.replace( + new RegExp(escapeRegExp( replacement.from ), 'g' ), + replacement.to + ) + } }) return content; @@ -1484,7 +1468,7 @@ class Notion { async Add( title, content, callback ) { if ( this.save_image ) { - content = await this.UploadImages(content) + content = await this.UploadImages( content ); } this.TempFile( this.folder_id, title, ( documentId, error ) => { console.log( 'TempFile: ', documentId ) From 8fdf7173847371febed67cfceafc5254d44ac05e Mon Sep 17 00:00:00 2001 From: Kenshin Date: Mon, 22 Jun 2020 11:27:47 +0800 Subject: [PATCH 26/30] Format source. --- src/options/corb.js | 4 ++-- src/service/export.js | 4 ++-- src/service/message.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/options/corb.js b/src/options/corb.js index 5bec9b9bd..e9819f80f 100644 --- a/src/options/corb.js +++ b/src/options/corb.js @@ -36,7 +36,7 @@ browser.runtime.onMessage.addListener( function( request, sender, sendResponse ) const downLoadCache = new Map(); browser.runtime.onMessage.addListener( async function ( request, sender, sendResponse ) { - if ( request.type == msg.MESSAGE_ACTION.NOTION_DL_IMG ) { + if ( request.type == msg.MESSAGE_ACTION.notion_dl_img ) { try { const option = request.value, { url, protocol } = option, @@ -57,7 +57,7 @@ browser.runtime.onMessage.addListener( async function ( request, sender, sendRes } catch ( err ) { sendResponse({ fail: err }); } - } else if ( request.type == msg.MESSAGE_ACTION.NOTION_UP_IMG ) { + } else if ( request.type == msg.MESSAGE_ACTION.notion_up_img ) { try { const option = request.value, { url, upUrl } = option, diff --git a/src/service/export.js b/src/service/export.js index c1cd383e7..d49744e2b 100644 --- a/src/service/export.js +++ b/src/service/export.js @@ -1386,7 +1386,7 @@ class Notion { DonwloadOriginImage( url ) { return new Promise(( resolve, reject ) => { browser.runtime.sendMessage( - msg.Add( msg.MESSAGE_ACTION.NOTION_DL_IMG, { + msg.Add( msg.MESSAGE_ACTION.notion_dl_img, { url, protocol: window.location.protocol }), res => { @@ -1402,7 +1402,7 @@ class Notion { this.UUID(), urls => { browser.runtime.sendMessage( - msg.Add( msg.MESSAGE_ACTION.NOTION_UP_IMG, { + msg.Add( msg.MESSAGE_ACTION.notion_up_img, { url: url, upUrl: urls.signedPutUrl, }), res => { diff --git a/src/service/message.js b/src/service/message.js index 54166e404..82668d8d4 100644 --- a/src/service/message.js +++ b/src/service/message.js @@ -54,8 +54,8 @@ const action = { tips : "tips", tips_norepeat : "tips_norepeat", // notion.so - NOTION_DL_IMG : "notion_dl_img", - NOTION_UP_IMG : "notion_up_img", + notion_dl_img : "notion_dl_img", + notion_up_img : "notion_up_img", }; /** From dbcb4e0abb10d59b1036c63d4229c9814a8b93b6 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Mon, 22 Jun 2020 11:56:18 +0800 Subject: [PATCH 27/30] Fix export notion header format bug. --- src/service/output.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service/output.js b/src/service/output.js index 853f41006..df263ffc8 100644 --- a/src/service/output.js +++ b/src/service/output.js @@ -319,7 +319,7 @@ function action( type, title, desc, content ) { notion.save_image = storage.secret.notion.save_image; notion.schema = storage.secret.notion.schema; notion.type = storage.secret.notion.type; - notion.Add( title, result.replace( /.jpeg!720/ig, '.jpeg' ), ( result, error ) => { + notion.Add( title, result.replace( /.jpeg!720/ig, '.jpeg' ).replace( /, 原文地址 \S+\)/i, '\n' ), ( result, error ) => { // hack code if ( notion.type == "collection" && notion.schema != storage.secret.notion.schema ) { storage.secret.notion.schema = notion.schema; From 3330d6877f8d242d10ada6078265be8e1c2cabba Mon Sep 17 00:00:00 2001 From: Kenshin Date: Mon, 22 Jun 2020 11:58:03 +0800 Subject: [PATCH 28/30] Format source. --- src/service/storage.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/service/storage.js b/src/service/storage.js index 133b775e5..fe4113d9a 100644 --- a/src/service/storage.js +++ b/src/service/storage.js @@ -253,6 +253,7 @@ let current = {}, "notion" : { access_token : "", type : "", + save_image : false, folder_id : "", }, "youdao" : { From 6d5b422f09cff5ac95264037e6ed0424219eab2b Mon Sep 17 00:00:00 2001 From: Kenshin Date: Mon, 22 Jun 2020 12:14:17 +0800 Subject: [PATCH 29/30] Update version to 1.1.4.6022. --- src/manifest.json | 2 +- src/service/version.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/manifest.json b/src/manifest.json index 443aedc2e..d1607b598 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,7 +1,7 @@ { "name" : "__MSG_extension_name__", "default_locale" : "en", - "version" : "1.1.4.6016", + "version" : "1.1.4.6022", "short_name" : "SimpRead", "description" : "__MSG_extension_desc__", "homepage_url" : "http://ksria.com/simpread", diff --git a/src/service/version.js b/src/service/version.js index 6034da9d3..e6c3d1af7 100644 --- a/src/service/version.js +++ b/src/service/version.js @@ -37,6 +37,7 @@ const version = browser.runtime.getManifest().version.replace( /.\d{2,}/, "" ), ]), patchs = new Map([ [ "1.1.4.6016", "修复 Notion 相关问题,并支持 Database 导出方案," ], + [ "1.1.4.6022", "修复 Notion 授权问题,并支持 图床 导出方案," ], ]), tips = { "root" : value => `.version-tips[data-hits='${value}']`, From 932ddd135fc4b1628ba471971c7578ad0a420eda Mon Sep 17 00:00:00 2001 From: Kenshin Date: Mon, 22 Jun 2020 12:34:34 +0800 Subject: [PATCH 30/30] Format source. --- src/service/output.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service/output.js b/src/service/output.js index df263ffc8..5bcb5978a 100644 --- a/src/service/output.js +++ b/src/service/output.js @@ -319,7 +319,7 @@ function action( type, title, desc, content ) { notion.save_image = storage.secret.notion.save_image; notion.schema = storage.secret.notion.schema; notion.type = storage.secret.notion.type; - notion.Add( title, result.replace( /.jpeg!720/ig, '.jpeg' ).replace( /, 原文地址 \S+\)/i, '\n' ), ( result, error ) => { + notion.Add( title, result.replace( /.(png|jpe?g)!\d+/ig, '.$1' ).replace( /, 原文地址 \S+\)/i, '\n' ), ( result, error ) => { // hack code if ( notion.type == "collection" && notion.schema != storage.secret.notion.schema ) { storage.secret.notion.schema = notion.schema;