diff --git a/src/index.ts b/src/index.ts
index bb67099..6560087 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -16,15 +16,16 @@
* along with this program. If not, see .
*/
-import {AwsClient} from 'aws4fetch';
-import {customAlphabet} from 'nanoid';
-import {sha256} from 'js-sha256';
+import { AwsClient } from 'aws4fetch';
+import { customAlphabet } from 'nanoid';
+import { sha256 } from 'js-sha256';
import dedent from 'dedent-js';
+import { PasteIndexEntry } from './types';
// Constants
const SERVICE_URL = 'pb.nekoid.cc';
-const PASTE_WEB_URL_v1 = 'https://raw.githubusercontent.com/rikkaneko/paste/main/web/v1';
-const PASTE_WEB_URL = 'https://raw.githubusercontent.com/rikkaneko/paste/main/web/v2';
+const PASTE_WEB_URL_v1 = 'https://raw.githubusercontent.com/rikkaneko/paste/main/static/v1';
+const PASTE_WEB_URL = 'https://raw.githubusercontent.com/rikkaneko/paste/main/static/v2';
const UUID_LENGTH = 4;
export interface Env {
@@ -35,23 +36,20 @@ export interface Env {
ENDPOINT: string;
}
-const gen_id = customAlphabet(
- '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', UUID_LENGTH);
+const gen_id = customAlphabet('1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', UUID_LENGTH);
export default {
- async fetch(
- request: Request,
- env: Env,
- ctx: ExecutionContext,
- ): Promise {
- const {url, method, headers} = request;
- const {pathname, searchParams} = new URL(url);
+ async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise {
+ const { url, method, headers } = request;
+ const { pathname, searchParams } = new URL(url);
const path = pathname.replace(/\/+$/, '') || '/';
let cache = caches.default;
const agent = headers.get('user-agent') ?? '';
// Detect if request from browsers
- const is_browser = ['Chrome', 'Mozilla', 'AppleWebKit', 'Safari', 'Gecko', 'Chromium'].some(v => agent.includes(v));
+ const is_browser = ['Chrome', 'Mozilla', 'AppleWebKit', 'Safari', 'Gecko', 'Chromium'].some((v) =>
+ agent.includes(v)
+ );
const s3 = new AwsClient({
accessKeyId: env.AWS_ACCESS_KEY_ID,
@@ -200,10 +198,12 @@ export default {
// Check password rules
if (password && !check_password_rules(password)) {
- return new Response('Invalid password. ' +
- 'Password must contain alphabets and digits only, and has a length of 4 or more.', {
- status: 422,
- });
+ return new Response(
+ 'Invalid password. ' + 'Password must contain alphabets and digits only, and has a length of 4 or more.',
+ {
+ status: 422,
+ }
+ );
}
// Check request.body size <= 25MB
@@ -239,16 +239,14 @@ export default {
};
// Key will be expired after 28 day if unmodified
- ctx.waitUntil(env.PASTE_INDEX.put(uuid, JSON.stringify(descriptor), {expirationTtl: 2419200}));
+ ctx.waitUntil(env.PASTE_INDEX.put(uuid, JSON.stringify(descriptor), { expirationTtl: 2419200 }));
return await get_paste_info(uuid, descriptor, env, is_browser, need_qrcode, reply_json);
} else {
return new Response('Unable to upload the paste.\n', {
status: 500,
});
}
-
}
-
} else if (path.length >= UUID_LENGTH + 1) {
// RegExpr to match //