chore: remove @affine/workers (#10084)

It was moved to https://github.com/toeverything/affine-workers
This commit is contained in:
Brooooooklyn
2025-02-11 11:17:58 +00:00
parent 39eb8625d6
commit c6932a8ae4
5 changed files with 7 additions and 645 deletions
+1 -7
View File
@@ -739,11 +739,6 @@ export const PackageList = [
name: '@affine-tools/utils',
workspaceDependencies: [],
},
{
location: 'tools/workers',
name: '@affine/workers',
workspaceDependencies: [],
},
];
export type PackageName =
@@ -819,5 +814,4 @@ export type PackageName =
| '@affine/commitlint-config'
| '@affine/copilot-result'
| '@affine/playstore-auto-bump'
| '@affine-tools/utils'
| '@affine/workers';
| '@affine-tools/utils';
-11
View File
@@ -1,11 +0,0 @@
{
"name": "@affine/workers",
"version": "0.19.0",
"private": true,
"scripts": {
"dev": "wrangler dev"
},
"devDependencies": {
"wrangler": "^3.95.0"
}
}
-73
View File
@@ -1,73 +0,0 @@
const ALLOW_ORIGIN = [
'https://affine.pro',
'https://app.affine.pro',
'https://insider.affine.pro',
'https://affine.fail',
];
function isString(s: any): boolean {
return typeof s === 'string' || s instanceof String;
}
function isOriginAllowed(
origin: string,
allowedOrigin: string | RegExp | Array<string | RegExp>
): boolean {
if (Array.isArray(allowedOrigin)) {
for (const allowed of allowedOrigin) {
if (isOriginAllowed(origin, allowed)) {
return true;
}
}
return false;
} else if (isString(allowedOrigin)) {
return origin === allowedOrigin;
} else if (allowedOrigin instanceof RegExp) {
return allowedOrigin.test(origin);
} else {
return !!allowedOrigin;
}
}
async function proxyImage(request: Request): Promise<Response> {
const url = new URL(request.url);
const imageURL = url.searchParams.get('url');
if (!imageURL) {
return new Response('Missing "url" parameter', { status: 400 });
}
const imageRequest = new Request(imageURL, {
method: 'GET',
headers: request.headers,
});
const response = await fetch(imageRequest);
const modifiedResponse = new Response(response.body);
modifiedResponse.headers.set(
'Access-Control-Allow-Origin',
request.headers.get('Origin') ?? 'null'
);
modifiedResponse.headers.set('Vary', 'Origin');
modifiedResponse.headers.set('Access-Control-Allow-Methods', 'GET');
return modifiedResponse;
}
const handler = {
async fetch(request: Request) {
if (!isOriginAllowed(request.headers.get('Origin') ?? '', ALLOW_ORIGIN)) {
return new Response('unauthorized', { status: 401 });
}
const url = new URL(request.url);
if (url.pathname.startsWith('/proxy/image')) {
return await proxyImage(request);
}
return new Response('not found', { status: 404 });
},
};
export default handler;
-3
View File
@@ -1,3 +0,0 @@
compatibility_date = "2023-07-11"
main = "./src/index.ts"
name = "workers"