diff --git a/scripts/cloudflare/r2-dir-list/.gitignore b/scripts/cloudflare/r2-dir-list/.gitignore new file mode 100644 index 0000000..b80178d --- /dev/null +++ b/scripts/cloudflare/r2-dir-list/.gitignore @@ -0,0 +1,176 @@ +# user specific +src/config.ts +wrangler.toml + +# Logs + +logs +_.log +npm-debug.log_ +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) + +report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json + +# Runtime data + +pids +_.pid +_.seed +\*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover + +lib-cov + +# Coverage directory used by tools like istanbul + +coverage +\*.lcov + +# nyc test coverage + +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) + +.grunt + +# Bower dependency directory (https://bower.io/) + +bower_components + +# node-waf configuration + +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) + +build/Release + +# Dependency directories + +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) + +web_modules/ + +# TypeScript cache + +\*.tsbuildinfo + +# Optional npm cache directory + +.npm + +# Optional eslint cache + +.eslintcache + +# Optional stylelint cache + +.stylelintcache + +# Microbundle cache + +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history + +.node_repl_history + +# Output of 'npm pack' + +\*.tgz + +# Yarn Integrity file + +.yarn-integrity + +# dotenv environment variable files + +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) + +.cache +.parcel-cache + +# Next.js build output + +.next +out + +# Nuxt.js build / generate output + +.nuxt +dist + +# Gatsby files + +.cache/ + +# Comment in the public line in if your project uses Gatsby and not Next.js + +# https://nextjs.org/blog/next-9-1#public-directory-support + +# public + +# vuepress build output + +.vuepress/dist + +# vuepress v2.x temp and cache directory + +.temp +.cache + +# Docusaurus cache and generated files + +.docusaurus + +# Serverless directories + +.serverless/ + +# FuseBox cache + +.fusebox/ + +# DynamoDB Local files + +.dynamodb/ + +# TernJS port file + +.tern-port + +# Stores VSCode versions used for testing VSCode extensions + +.vscode-test + +# yarn v2 + +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.\* + +# wrangler project + +.dev.vars +.wrangler/ diff --git a/scripts/cloudflare/r2-dir-list/LICENSE b/scripts/cloudflare/r2-dir-list/LICENSE new file mode 100644 index 0000000..42c809e --- /dev/null +++ b/scripts/cloudflare/r2-dir-list/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Mingjun Cao + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/scripts/cloudflare/r2-dir-list/README.md b/scripts/cloudflare/r2-dir-list/README.md new file mode 100644 index 0000000..0ba3494 --- /dev/null +++ b/scripts/cloudflare/r2-dir-list/README.md @@ -0,0 +1,40 @@ +# R2 Directory Listing + +This is a simple Directory Listing script for [Cloudflare R2](https://developers.cloudflare.com/r2/) and hosted on [Cloudflare Workers](https://workers.cloudflare.com/). It is inspired by the [Directory Listing of Gitea downloads site](https://blog.gitea.com/evolution-of-the-gitea-downloads-site/). + +## Usage + +Clone this repository, install dependencies and edit the configs: + +```bash +git clone https://github.com/cmj2002/r2-dir-list.git +cd r2-dir-list +npm install +mv src/config.ts.example src/config.ts +mv wrangler.toml.example wrangler.toml +``` + +You should edit: +- `bucketname` in `src/config.ts` and `wrangler.toml` to your bucket name. +- `bucketdomain.example.com` in `src/config.ts` and `wrangler.toml` to your bucket domain. **It must have been set as a [custom domain](https://developers.cloudflare.com/r2/buckets/public-buckets/#custom-domains) of your Cloudflare R2 bucket**. +- `example.com` in `wrangler.toml`'s `zone_name` to yours. +- Other settings like `name`, `desp`, `showPoweredBy` and `legalInfo` in `src/config.ts` to your own. + +You may want to search `bucketdomain`, `bucketname` and `example.com` in your code to ensure you have edited all of them. + +Then you can run `wrangler deploy` to deploy it to your Cloudflare Workers. + +## Demo + +https://datasets.caomingjun.com/ + +This is a production website of mine, which hosts some machine learning datasets used in my papers and codes to share with other reserchers. It is a Cloudflare R2 bucket with this worker in front of it. + +## How it works + +It will only overwrite the response when all of the following conditions are met: +- Response from R2 has a status of 404 +- The requested pathname ends with `/` +- There exist "subdirectories" or "files" under the current "directory" (The quotation marks here are used because directories and files are abstract concepts in object storage) + +In such a case, it will generate a HTML page with the list of "subdirectories" and "files" under the current "directory" and return it. Otherwise, it will just return the response from R2. So **putting this worker in front of your R2 bucket will not affect any normal access to your bucket**. diff --git a/scripts/cloudflare/r2-dir-list/package.json b/scripts/cloudflare/r2-dir-list/package.json new file mode 100644 index 0000000..7987d4c --- /dev/null +++ b/scripts/cloudflare/r2-dir-list/package.json @@ -0,0 +1,15 @@ +{ + "name": "s3-dir-list", + "version": "0.0.0", + "private": true, + "scripts": { + "deploy": "wrangler deploy", + "dev": "wrangler dev", + "start": "wrangler dev" + }, + "devDependencies": { + "@cloudflare/workers-types": "^4.20230419.0", + "typescript": "^5.0.4", + "wrangler": "^3.0.0" + } +} \ No newline at end of file diff --git a/scripts/cloudflare/r2-dir-list/src/index.ts b/scripts/cloudflare/r2-dir-list/src/index.ts new file mode 100644 index 0000000..7e800f8 --- /dev/null +++ b/scripts/cloudflare/r2-dir-list/src/index.ts @@ -0,0 +1,43 @@ +import { Env } from './types'; +import { renderTemplFull } from './render'; +import { getSiteConfig } from './config'; + +export default { + async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise { + const originResponse = await fetch(request); + // if status is not 404 or request path not end with '/', return origin response + if ((originResponse.status !== 404) || (originResponse.url.slice(-1) !== '/')) { + return originResponse; + } + const url = new URL(request.url); + const domain = url.hostname; + const path = url.pathname; + // remove the leading '/' + const objectKey = path.slice(1); + const siteConfig = getSiteConfig(env, domain); + if (!siteConfig) { + // TODO: Should send a email to notify the admin + return originResponse; + } + const bucket = siteConfig.bucket; + const index = await bucket.list({ + // TODO: Should manage limit here, but since I won't have more than 1000 files in a single folder, I just ignore it + prefix: objectKey, + delimiter: '/', + include: ['httpMetadata', 'customMetadata'] + }); + // if no object found, return origin response + if (index.objects.length === 0 && index.delimitedPrefixes.length === 0) { + return originResponse; + } + return new Response( + renderTemplFull(index.objects, index.delimitedPrefixes, path, siteConfig), + { + headers: { + 'Content-Type': 'text/html; charset=utf-8', + }, + status: 200, + }, + ); + }, +}; diff --git a/scripts/cloudflare/r2-dir-list/src/render.ts b/scripts/cloudflare/r2-dir-list/src/render.ts new file mode 100644 index 0000000..85e82ca --- /dev/null +++ b/scripts/cloudflare/r2-dir-list/src/render.ts @@ -0,0 +1,197 @@ +import { svgs, cssStyle, defaultFavicon } from './static'; +import { SiteConfig } from './types'; + +export var renderTemplFull = (files: R2Object[], folders: string[], path: string, config: SiteConfig) => { + return ` + + + + + + ${renderTemplTitle(config.name, path)} + ${cssStyle} + + + ${svgs} +
+

+ + ${config.name} / + ${renderTemplBreadcrumbs(path)} +

+
+
+
+ + + + + + + + + + + + + ${(path==='/')?'':renderGoUp(path)} + ${renderTemplFolders(folders, config)} + ${renderTemplFiles(files, config)} + +
NameDescriptionSizeModified
+
+
+ + + + `; +} + +var renderGoUp = (path: string) => { + if(path !== "") { + return ` + + + + + Go up + + + — + — + — + + `; + } + return ''; +} + +var renderTemplTitle = (siteTitle:string, path: string) => { + if(path === "/") { + return siteTitle + } + path = path.slice(0, -1); + return `${siteTitle} | ${cleanTitle(path)}`; +} + +var cleanTitle = (path: string) => { + var parts = path.split("/") + // remove the empty strings + parts = parts.filter((part) => part !== "") + return parts[parts.length-1] +} + +var renderTemplBreadcrumbs = (path: string) => { + const parts = path.split('/'); + var output = ''; + var currentPath = '/'; + for (var i = 0; i < parts.length; i++) { + if (parts[i] === '') continue; + currentPath += parts[i] + '/'; + output += `${parts[i]} / `; + } + console.log(output); + return output; +} + +var renderTemplFolders = (folders: string[], siteConfig: SiteConfig) => { + if(typeof folders === 'undefined') return ''; + var output = ''; + for (var i = 0; i < folders.length; i++) { + output += ` + + ${cleanFolderName(folders[i])} + ${findDesp(siteConfig, '/'+folders[i].slice(0, -1), true)??"—"} + — + — + + `; + } + return output; +} + + +var renderTemplFiles = (files: R2Object[], siteConfig: SiteConfig) => { + if(typeof files === 'undefined') return ''; + var output = ''; + for (var i = 0; i < files.length; i++) { + output += ` + + ${cleanFileName(files[i].key)} + ${findDesp(siteConfig, '/'+files[i].key, true)??"—"} + ${humanFileSize(files[i].size)} + + + `; + } + return output; +} + +var cleanFileName = (name: string) => { + return name.split("/").slice(-1).pop()! +} + +var cleanFolderName = (name: string) => { + return name.slice(0, -1).split("/").slice(-1).pop()! +} + +// taken from https://stackoverflow.com/questions/10420352/converting-file-size-in-bytes-to-human-readable-string +var humanFileSize = (bytes: number, si=false, dp=1) => { + const thresh = si ? 1000 : 1024; + + if (Math.abs(bytes) < thresh) { + return bytes + ' B'; + } + + const units = si + ? ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] + : ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']; + let u = -1; + const r = 10**dp; + + do { + bytes /= thresh; + ++u; + } while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1); + + + return bytes.toFixed(dp) + ' ' + units[u]; +} + +function findDesp(siteConfig: SiteConfig, path: string, exact: boolean): string | undefined { + if (exact) { + return siteConfig.desp[path]; + } + const keys = Object.keys(siteConfig.desp); + // find the longest match + let longestMatch = '/'; + for (const key of keys) { + if (path.startsWith(key) && key.length > longestMatch.length) { + longestMatch = key; + } + } + const desp = siteConfig.desp[longestMatch]; + return desp; +} + +function generateFooter(siteConfig: SiteConfig, path: string): string { + /// Footer includes: + /// - desp of current path, use the most specific entry + /// - legal info, if any + /// - reference to gitea download site code, as the inspiration of this project + + let contents:string[] = []; + const desp = findDesp(siteConfig, path, false); + if (desp) { + contents.push(`

${desp}

`); + } + if (siteConfig.legalInfo) { + contents.push(`

${siteConfig.legalInfo}

`); + } + if (siteConfig.showPoweredBy) { + contents.push(`

Powered by r2-dir-list

`); + } + return contents.join(''); +} \ No newline at end of file diff --git a/scripts/cloudflare/r2-dir-list/src/static.ts b/scripts/cloudflare/r2-dir-list/src/static.ts new file mode 100644 index 0000000..750277a --- /dev/null +++ b/scripts/cloudflare/r2-dir-list/src/static.ts @@ -0,0 +1,206 @@ +const svgs = ` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + `; + + +const cssStyle = ``; + +const defaultFavicon='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAACXBIWXMAAAAAAAAAAQCEeRdzAAAPCklEQVR4nO2dB3AbZRbHXeQmy7JsFVuyitMb6YEkTu/dSZxiYqf3QmzSKykQElroPSGE3g+OduFoIXTI0eFoCYRylIRycAfX7/jdzM7teSxpJUv6tv1n3oxG2u/73nv7tPuVV9LSTJgwYcKECRMmTJgwYcKECRMmNIJcS3pua1dW28Et8oZN62ybcVpv+4ozhxadc/UE1/W3n+q57/6ZJY8eWug7/MppZe++u9L/6afrgt9Cn60PfvfjtvJ/y4n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L7NtVlTuH4llSpSmau8RBeNwST4l6Fm3l1p/xaSsWQgUTEkpExyeABD/ACT/AGj8nyVvp6U+gnPKtVfVTO2pWj3GQoIJJx/DJz/pjE0oSeXzXetW/70KJdLKUoOFXT2Tazsp21Sor8oQAV0UBy4jvpd66lDW3pg77ok74J1GAsDqpSKSNeSZpKmMX7LhHvOqMTOlRSe1m1MMvFxEdS2RhVP+5jASVSeZxG29o0MlFBhJUQqWJE36+kAYvmqYDv36vLy94TrXTRRDk61vO4vhvy/ANrp8omNf6aUkBZK0QSbIJekLmFM6uVaP2rCjwd8LWv7WKbzR4AM+5kLStTQfDOygRZkIkVkm7e6akCmyrE0I1rZ524ql/hBg6gyDBOmTU1TCzhAV7gCd7gEV55smlp80qT4PSMx+iAZrmDp3bMr2GThCRMeBPfUu25h4DTgwu8L5Jx850V/mNE/kgkL9vOZ/lvrPNpQ1v6oC/6pG/GYCwqnDO2ebppwoQJEyZMmDBhwoQJEyZMmNAC/gN26Zo03XFMmQAAAABJRU5ErkJggg==' + +export { svgs, cssStyle, defaultFavicon }; \ No newline at end of file diff --git a/scripts/cloudflare/r2-dir-list/src/types.ts b/scripts/cloudflare/r2-dir-list/src/types.ts new file mode 100644 index 0000000..92b59ab --- /dev/null +++ b/scripts/cloudflare/r2-dir-list/src/types.ts @@ -0,0 +1,14 @@ +export type Env = { + [K in `BUCKET_${string}`]: R2Bucket; +}; + +export interface SiteConfig { + name: string; + bucket: R2Bucket; + desp: { + [path: string]: string; + }; + legalInfo?: string; + showPoweredBy?: boolean; + favicon?: string; +} \ No newline at end of file diff --git a/scripts/cloudflare/r2-dir-list/tsconfig.json b/scripts/cloudflare/r2-dir-list/tsconfig.json new file mode 100644 index 0000000..e793a16 --- /dev/null +++ b/scripts/cloudflare/r2-dir-list/tsconfig.json @@ -0,0 +1,101 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig.json to read more about this file */ + + /* Projects */ + // "incremental": true, /* Enable incremental compilation */ + // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ + // "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */ + // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */ + // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ + // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ + + /* Language and Environment */ + "target": "es2021" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, + "lib": ["es2021"] /* Specify a set of bundled library declaration files that describe the target runtime environment. */, + "jsx": "react" /* Specify what JSX code is generated. */, + // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ + // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ + // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */ + // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ + // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */ + // "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */ + // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ + // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + + /* Modules */ + "module": "es2022" /* Specify what module code is generated. */, + // "rootDir": "./", /* Specify the root folder within your source files. */ + "moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */, + // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ + // "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */ + "types": ["@cloudflare/workers-types/2023-03-01"] /* Specify type package names to be included without being referenced in a source file. */, + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + "resolveJsonModule": true /* Enable importing .json files */, + // "noResolve": true, /* Disallow `import`s, `require`s or ``s from expanding the number of files TypeScript should add to a project. */ + + /* JavaScript Support */ + "allowJs": true /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */, + "checkJs": false /* Enable error reporting in type-checked JavaScript files. */, + // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */ + + /* Emit */ + // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ + // "declarationMap": true, /* Create sourcemaps for d.ts files. */ + // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ + // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ + // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ + // "outDir": "./", /* Specify an output folder for all emitted files. */ + // "removeComments": true, /* Disable emitting comments. */ + "noEmit": true /* Disable emitting files from a compilation. */, + // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ + // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */ + // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ + // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ + // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ + // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ + // "newLine": "crlf", /* Set the newline character for emitting files. */ + // "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */ + // "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */ + // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ + // "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */ + // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ + // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ + + /* Interop Constraints */ + "isolatedModules": true /* Ensure that each file can be safely transpiled without relying on other imports. */, + "allowSyntheticDefaultImports": true /* Allow 'import x from y' when a module doesn't have a default export. */, + // "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */, + // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ + "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, + + /* Type Checking */ + "strict": true /* Enable all strict type-checking options. */, + // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */ + // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */ + // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ + // "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */ + // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ + // "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */ + // "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */ + // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ + // "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */ + // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */ + // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ + // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ + // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ + // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */ + // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ + // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ + + /* Completeness */ + // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ + "skipLibCheck": true /* Skip type checking all .d.ts files. */ + } +} diff --git a/scripts/cloudflare/indexer/.gitignore b/scripts/cloudflare/r2-indexer/.gitignore similarity index 100% rename from scripts/cloudflare/indexer/.gitignore rename to scripts/cloudflare/r2-indexer/.gitignore diff --git a/scripts/cloudflare/indexer/package.json b/scripts/cloudflare/r2-indexer/package.json similarity index 80% rename from scripts/cloudflare/indexer/package.json rename to scripts/cloudflare/r2-indexer/package.json index 5e9a513..86a7b94 100644 --- a/scripts/cloudflare/indexer/package.json +++ b/scripts/cloudflare/r2-indexer/package.json @@ -1,6 +1,4 @@ { - "name": "indexer", - "version": "0.0.0", "private": true, "scripts": { "deploy": "wrangler deploy", @@ -10,4 +8,4 @@ "devDependencies": { "wrangler": "^3.0.0" } -} \ No newline at end of file +} diff --git a/scripts/cloudflare/indexer/src/index.js b/scripts/cloudflare/r2-indexer/src/index.js similarity index 100% rename from scripts/cloudflare/indexer/src/index.js rename to scripts/cloudflare/r2-indexer/src/index.js diff --git a/scripts/cloudflare/indexer/wrangler.toml b/scripts/cloudflare/r2-indexer/wrangler.toml similarity index 99% rename from scripts/cloudflare/indexer/wrangler.toml rename to scripts/cloudflare/r2-indexer/wrangler.toml index 3100f71..b848b2a 100644 --- a/scripts/cloudflare/indexer/wrangler.toml +++ b/scripts/cloudflare/r2-indexer/wrangler.toml @@ -1,4 +1,4 @@ -name = "indexer" +name = "r2-indexer" main = "src/index.js" compatibility_date = "2023-12-18" diff --git a/scripts/cloudflare/indexer/yarn.lock b/scripts/cloudflare/r2-indexer/yarn.lock similarity index 100% rename from scripts/cloudflare/indexer/yarn.lock rename to scripts/cloudflare/r2-indexer/yarn.lock