Skip to content

Commit

Permalink
Merge branch 'release/1.1.4.6022'
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenshin committed Jun 23, 2020
2 parents c493eeb + 932ddd1 commit 7aa2181
Show file tree
Hide file tree
Showing 9 changed files with 433 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
20 changes: 16 additions & 4 deletions src/module/authorize.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,15 @@ 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() );
state == "notion_save_image" && ( storage.secret.notion.save_image = value );
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 );
obj.type == "page" && delete storage.secret.notion.schema;
}
storage.Safe( () => this.setState({ secret: storage.secret }), storage.secret );
}

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

{ this.state.secret.notion.access_token &&
<div style={{ display: "flex","flex-direction": "row", "justify-content": "center" }}>
<div style={{ display: "flex","flex-direction": "column", "justify-content": "center" }}>
{ this.state.notion ? <Dropdown name={ "请选择保存的位置,默认为第一个" } items={ this.state.notion } width="100%" onChange={ (v,n)=>this.save( "notion", v ) } />
: <Button type="flat" width="100%" style={{ "margin": "0" }}
text="重新获取 Notion Page"
color="#fff" backgroundColor="#3F51B5"
waves="md-waves-effect md-waves-button"
onClick={ (s)=>this.notionChange() } /> }
</div> }

<Switch width="100%" checked={ this.state.secret.notion.save_image }
thumbedColor="#3F51B5" trackedColor="#7986CB" waves="md-waves-effect"
label="是否使用 Notion.so 作为图床?"
desc="由于 Notion 并未公开 API 所以此方式较慢。"
onChange={ (s)=>this.save( "notion_save_image", s ) } />
</div>}
</div>
<div className="version-tips" data-version="1.1.4" data-hits="youdao">
<Switch width="100%" checked={ this.state.secret.youdao.access_token != "" ? true : false }
Expand Down
52 changes: 52 additions & 0 deletions src/options/corb.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,59 @@ 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 }));
}
}
return true;
});

/**
* Listen runtime message, include: `notion`
*/
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,
{ url, protocol } = option,
dlRes = await axios({ method: 'get', url: url.replace( /https?:/, protocol ), 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,
{ url, upUrl } = option,
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;
});
Loading

0 comments on commit 7aa2181

Please sign in to comment.