@@ -6,7 +6,7 @@ import migrate from '@/utils/migration';
66import download , { downloadFile } from '@/utils/download' ;
77import { syncArtifacts , produceArtifact } from '@/restful/sync' ;
88import { gistBackupAction } from '@/restful/miscs' ;
9- import { TOKENS_KEY } from '@/constants' ;
9+ import { TOKENS_KEY , SETTINGS_KEY } from '@/constants' ;
1010
1111import registerSubscriptionRoutes from './subscriptions' ;
1212import registerCollectionRoutes from './collections' ;
@@ -71,12 +71,26 @@ export default function serve() {
7171 const token = tokens . find (
7272 ( t ) =>
7373 t . token === req . query . token &&
74- `/share/${ t . type } /${ t . name } ` === pathname &&
74+ ( `/share/${ t . type } /${ t . name } ` === pathname ||
75+ pathname . startsWith (
76+ `/share/${ t . type } /${ t . name } /` ,
77+ ) ) &&
7578 ( t . exp == null || t . exp > Date . now ( ) ) ,
7679 ) ;
7780 if ( token ) {
7881 next ( ) ;
7982 return ;
83+ } else {
84+ const settings = $ . read ( SETTINGS_KEY ) ;
85+ if ( settings ?. appearanceSetting ?. invalidShareFakeNode ) {
86+ req . query . _fakeNode = true ;
87+ req . url = req . url . replace (
88+ / \/ s h a r e \/ .* ?\/ / ,
89+ '/share/sub/' ,
90+ ) ;
91+ next ( ) ;
92+ return ;
93+ }
8094 }
8195 }
8296 if ( be_merge && fe_path && req . path . indexOf ( '/' , 1 ) == - 1 ) {
@@ -378,7 +392,22 @@ export default function serve() {
378392 t . name === req . params . name &&
379393 ( t . exp == null || t . exp > Date . now ( ) ) ,
380394 ) ;
381- if ( ! token ) throw new Error ( 'Forbbiden' ) ;
395+ if ( ! token ) {
396+ const settings = $ . read ( SETTINGS_KEY ) ;
397+ if (
398+ settings ?. appearanceSetting
399+ ?. invalidShareFakeNode
400+ ) {
401+ return req . originalUrl
402+ . replace (
403+ / \/ s h a r e \/ .* ?\/ / ,
404+ '/share/sub/' ,
405+ )
406+ . replace ( '?' , '?_fakeNode=true&' ) ;
407+ } else {
408+ return '/404' ;
409+ }
410+ }
382411 return req . originalUrl ;
383412 } ,
384413 } ) ,
0 commit comments