fix: google snapshots error #649

This commit is contained in:
shuai
2023-11-27 15:24:05 +08:00
parent 0267f4bd69
commit 3eeb289aa0
3 changed files with 1234 additions and 183 deletions
+1212 -183
View File
File diff suppressed because it is too large Load Diff
+3
View File
@@ -110,6 +110,9 @@ const routes: RouteNode[] = [
{
path: '/search',
page: 'pages/Search',
guard: () => {
return guard.googleSnapshotRedirect();
},
},
// tags
{
+19
View File
@@ -401,6 +401,25 @@ export const initAppSettingsStore = async () => {
}
};
export const googleSnapshotRedirect = () => {
const gr: TGuardResult = { ok: true };
const searchStr = new URLSearchParams(window.location.search)?.get('q') || '';
if (window.location.host !== 'webcache.googleusercontent.com') {
return gr;
}
if (searchStr.indexOf('cache:') === 0 && searchStr.includes(':http')) {
const redirectUrl = `http${searchStr.split(':http')[1]}`;
const pathname = redirectUrl.replace(new URL(redirectUrl).origin, '');
console.log('googleSnapshotUrl', window.location.href);
gr.ok = false;
gr.redirect = pathname || '/';
return gr;
}
return gr;
};
let appInitialized = false;
export const setupApp = async () => {
/**