Skip to content

Commit 7aa2181

Browse files
committed
Merge branch 'release/1.1.4.6022'
2 parents c493eeb + 932ddd1 commit 7aa2181

File tree

9 files changed

+433
-24
lines changed

9 files changed

+433
-24
lines changed

src/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name" : "__MSG_extension_name__",
33
"default_locale" : "en",
4-
"version" : "1.1.4.6016",
4+
"version" : "1.1.4.6022",
55
"short_name" : "SimpRead",
66
"description" : "__MSG_extension_desc__",
77
"homepage_url" : "http://ksria.com/simpread",

src/module/authorize.jsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,15 @@ export default class Auth extends React.Component {
287287
save( state, value ) {
288288
state == "pocket" && ( storage.secret.pocket.tags = value.trim() );
289289
state == "linnk" && ( storage.secret.linnk.group_name = value.trim() );
290-
state == "notion" && ( storage.secret.notion.folder_id = value.trim() );
291-
state == "notion" && ( storage.secret.notion.type = this.state.notion.filter( item => item.value == value.trim() )[0].type );
292290
state == "youdao" && ( storage.secret.youdao.folder_id = value.trim() );
291+
state == "notion_save_image" && ( storage.secret.notion.save_image = value );
292+
if ( state == 'notion' ) {
293+
const obj = this.state.notion.filter( item => item.value == value.trim() )[0];
294+
storage.secret.notion.folder_id = value.trim();
295+
storage.secret.notion.type = obj.type;
296+
obj.schema && ( storage.secret.notion.schema = obj.schema );
297+
obj.type == "page" && delete storage.secret.notion.schema;
298+
}
293299
storage.Safe( () => this.setState({ secret: storage.secret }), storage.secret );
294300
}
295301

@@ -518,14 +524,20 @@ export default class Auth extends React.Component {
518524
onChange={ (s)=>this.onChange( "notion", s ) } />
519525

520526
{ this.state.secret.notion.access_token &&
521-
<div style={{ display: "flex","flex-direction": "row", "justify-content": "center" }}>
527+
<div style={{ display: "flex","flex-direction": "column", "justify-content": "center" }}>
522528
{ this.state.notion ? <Dropdown name={ "请选择保存的位置,默认为第一个" } items={ this.state.notion } width="100%" onChange={ (v,n)=>this.save( "notion", v ) } />
523529
: <Button type="flat" width="100%" style={{ "margin": "0" }}
524530
text="重新获取 Notion Page"
525531
color="#fff" backgroundColor="#3F51B5"
526532
waves="md-waves-effect md-waves-button"
527533
onClick={ (s)=>this.notionChange() } /> }
528-
</div> }
534+
535+
<Switch width="100%" checked={ this.state.secret.notion.save_image }
536+
thumbedColor="#3F51B5" trackedColor="#7986CB" waves="md-waves-effect"
537+
label="是否使用 Notion.so 作为图床?"
538+
desc="由于 Notion 并未公开 API 所以此方式较慢。"
539+
onChange={ (s)=>this.save( "notion_save_image", s ) } />
540+
</div>}
529541
</div>
530542
<div className="version-tips" data-version="1.1.4" data-hits="youdao">
531543
<Switch width="100%" checked={ this.state.secret.youdao.access_token != "" ? true : false }

src/options/corb.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,59 @@ browser.runtime.onMessage.addListener( function( request, sender, sendResponse )
2121
axios.put( request.value.url, request.value.content, request.value.data )
2222
.then( response => sendResponse({ done: response }))
2323
.catch( error => sendResponse({ fail: error }));
24+
} else if( request.value.type == 'download' ) {
25+
axios( request.value )
26+
.then( response => sendResponse({ done: response }))
27+
.catch( error => sendResponse({ fail: error }));
2428
}
2529
}
2630
return true;
2731
});
32+
33+
/**
34+
* Listen runtime message, include: `notion`
35+
*/
36+
const downLoadCache = new Map();
37+
38+
browser.runtime.onMessage.addListener( async function ( request, sender, sendResponse ) {
39+
if ( request.type == msg.MESSAGE_ACTION.notion_dl_img ) {
40+
try {
41+
const option = request.value,
42+
{ url, protocol } = option,
43+
dlRes = await axios({ method: 'get', url: url.replace( /https?:/, protocol ), responseType: 'blob', });
44+
let blob = dlRes.data;
45+
46+
if ( blob.type === 'image/webp' ) {
47+
blob = blob.slice( 0, blob.size, 'image/jpeg' );
48+
}
49+
downLoadCache.set( url, blob );
50+
sendResponse({
51+
done: {
52+
type: blob.type,
53+
size: blob.size,
54+
url,
55+
},
56+
});
57+
} catch ( err ) {
58+
sendResponse({ fail: err });
59+
}
60+
} else if ( request.type == msg.MESSAGE_ACTION.notion_up_img ) {
61+
try {
62+
const option = request.value,
63+
{ url, upUrl } = option,
64+
blob = downLoadCache.get( url );
65+
66+
await axios.put( upUrl, blob, {
67+
headers: {
68+
'Content-Type': blob.type,
69+
},
70+
});
71+
72+
downLoadCache.delete( url );
73+
sendResponse({ done: true });
74+
} catch ( err ) {
75+
sendResponse({ fail: err });
76+
}
77+
}
78+
return true;
79+
});

0 commit comments

Comments
 (0)