@@ -18,81 +18,85 @@ import {
1818// API calls that can be made from content scripts transit trough the background script
1919// This is done to prevent CORS errors
2020// Functions here aren't decoupled from the background script because of odd behavior with sendResponse
21- chrome . runtime . onMessageExternal . addListener (
22- ( message , sender , sendResponse ) => {
23- switch ( message . type ) {
24- case "chatgpt-to-notion_search" :
25- searchNotion ( message . body . query )
26- . then ( ( res ) => {
27- sendResponse ( res )
28- } )
29- . catch ( ( err ) => {
30- console . error ( err )
31- sendResponse ( { err } )
32- } )
33- break
34- case "chatgpt-to-notion_checkSaveConflict" :
35- checkSaveConflict ( message . body )
36- . then ( ( res ) => {
37- sendResponse ( res )
38- } )
39- . catch ( ( err ) => {
40- console . error ( err )
41- sendResponse ( { err } )
42- } )
43- break
44- case "chatgpt-to-notion_saveChat" :
45- saveChat ( message . body )
46- . then ( ( res ) => {
47- sendResponse ( res )
48- } )
49- . catch ( ( err ) => {
50- console . error ( err )
51- sendResponse ( { err } )
52- } )
53- break
54- case "chatgpt-to-notion_autoSave" :
55- const storage = new Storage ( )
56- saveChat ( message . body )
57- . then ( ( res ) => {
58- sendResponse ( res )
59- storage . set ( "autosaveStatus" , "saved" as AutosaveStatus )
60- } )
61- . catch ( ( err ) => {
62- storage . set ( "autosaveStatus" , "error" as AutosaveStatus )
63- console . error ( err )
64- sendResponse ( { err } )
65- } )
66- break
67- case "chatgpt-to-notion_generateToken" :
68- // using two means of checking if user is logged in just to be sure
69- const session = new Storage ( {
70- area : "session" ,
71- secretKeyList : [ "token" ]
21+ chrome . runtime . onMessage . addListener ( ( message , sender , sendResponse ) => {
22+ switch ( message . type ) {
23+ case "chatgpt-to-notion_search" :
24+ searchNotion ( message . body . query )
25+ . then ( ( res ) => {
26+ sendResponse ( res )
7227 } )
73- session . get ( "token" ) . then ( ( token ) => {
74- if ( token ) return
75- generateToken ( message . body . code ) . then ( ( res ) => {
76- sendResponse ( res )
77- } )
28+ . catch ( ( err ) => {
29+ console . error ( err )
30+ sendResponse ( { err } )
7831 } )
79- break
80- case "chatgpt-to-notion_getDB" :
81- getDatabase ( message . body . id )
32+ break
33+ case "chatgpt-to-notion_checkSaveConflict" :
34+ checkSaveConflict ( message . body )
35+ . then ( ( res ) => {
36+ sendResponse ( res )
37+ } )
38+ . catch ( ( err ) => {
39+ console . error ( err )
40+ sendResponse ( { err } )
41+ } )
42+ break
43+ case "chatgpt-to-notion_saveChat" :
44+ saveChat ( message . body )
45+ . then ( ( res ) => {
46+ sendResponse ( res )
47+ } )
48+ . catch ( ( err ) => {
49+ console . error ( err )
50+ sendResponse ( { err } )
51+ } )
52+ break
53+ case "chatgpt-to-notion_autoSave" :
54+ const storage = new Storage ( )
55+ saveChat ( message . body )
56+ . then ( ( res ) => {
57+ sendResponse ( res )
58+ storage . set ( "autosaveStatus" , "saved" as AutosaveStatus )
59+ } )
60+ . catch ( ( err ) => {
61+ storage . set ( "autosaveStatus" , "error" as AutosaveStatus )
62+ console . error ( err )
63+ sendResponse ( { err } )
64+ } )
65+ break
66+ case "chatgpt-to-notion_generateToken" :
67+ // using two means of checking if user is logged in just to be sure
68+ const session = new Storage ( {
69+ area : "session" ,
70+ secretKeyList : [ "token" ]
71+ } )
72+ session . get ( "token" ) . then ( ( token ) => {
73+ if ( token ) return
74+ generateToken ( message . body . code )
8275 . then ( ( res ) => {
76+ console . log ( res )
8377 sendResponse ( res )
8478 } )
8579 . catch ( ( err ) => {
8680 console . error ( err )
8781 sendResponse ( { err } )
8882 } )
89- break
90- default :
91- return true
92- }
93- return true
83+ } )
84+ break
85+ case "chatgpt-to-notion_getDB" :
86+ getDatabase ( message . body . id )
87+ . then ( ( res ) => {
88+ sendResponse ( res )
89+ } )
90+ . catch ( ( err ) => {
91+ console . error ( err )
92+ sendResponse ( { err } )
93+ } )
94+ break
95+ default :
96+ return true
9497 }
95- )
98+ return true
99+ } )
96100
97101chrome . runtime . onInstalled . addListener ( ( ) => {
98102 refreshContentScripts ( )
0 commit comments