r2-explorer 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/api/core.js DELETED
@@ -1,12 +0,0 @@
1
- export function JsonResponse(json, status = 200, headers = {}) {
2
- return new Response(JSON.stringify(json), {
3
- headers: {
4
- 'content-type': 'application/json;charset=UTF-8',
5
- 'access-control-allow-origin': '*',
6
- 'access-control-allow-headers': '*',
7
- 'access-control-allow-methods': '*',
8
- ...headers
9
- },
10
- status
11
- })
12
- }
@@ -1,13 +0,0 @@
1
- import { JsonResponse } from './core'
2
-
3
- export async function createFolder (request, env, context) {
4
- const body = await request.json()
5
-
6
- const { disk } = request.params
7
- const bucket = env[disk]
8
- const { path } = body
9
-
10
- const data = await bucket.put(path, 'Folder placeholder')
11
-
12
- return JsonResponse(data)
13
- }
@@ -1,15 +0,0 @@
1
- import { JsonResponse } from './core'
2
-
3
- export async function deleteObject (request, env, context) {
4
- const body = await request.json()
5
-
6
- const { disk } = request.params
7
- const bucket = env[disk]
8
-
9
- const { name } = body
10
- const { path } = body
11
-
12
- await bucket.delete(`${path}${name}`)
13
-
14
- return JsonResponse({})
15
- }
@@ -1,23 +0,0 @@
1
- export async function downloadFile(request, env, context) {
2
- const body = await request.json()
3
-
4
- const {disk} = request.params
5
- const bucket = env[disk]
6
-
7
- const {name} = body
8
- const {path} = body
9
-
10
- const object = await bucket.get(`${path}${name}`);
11
-
12
- if (object === null) {
13
- return new Response('Object Not Found', {status: 404});
14
- }
15
-
16
- const headers = new Headers();
17
- object.writeHttpMetadata(headers);
18
- headers.set('etag', object.httpEtag);
19
-
20
- return new Response(object.body, {
21
- headers,
22
- });
23
- }
@@ -1,27 +0,0 @@
1
- import { JsonResponse } from './core'
2
-
3
- export async function listContents (request, env, context) {
4
- const { disk } = request.params
5
- const bucket = env[disk]
6
-
7
- const { path } = request.query || ''
8
-
9
- const contents = []
10
- const prefixes = []
11
- const data = await bucket.list({prefix: path, delimiter: '/'})
12
-
13
- if(data.objects) {
14
- for(const obj of data.objects) {
15
- contents.push({Key: obj.key, Size: obj.size, LastModified: obj.uploaded})
16
- }
17
- }
18
-
19
- if(data.delimitedPrefixes) {
20
- for(const prefix of data.delimitedPrefixes) {
21
- prefixes.push({Prefix: prefix})
22
- }
23
- }
24
-
25
- return JsonResponse({Contents: contents, CommonPrefixes: prefixes})
26
- }
27
-
@@ -1,15 +0,0 @@
1
- import {JsonResponse} from './core'
2
-
3
- export async function listDisks(request, env, context) {
4
-
5
- const buckets = []
6
-
7
- for (const [key, value] of Object.entries(env)) {
8
- if(value.get && value.put) {
9
- buckets.push({Name: key})
10
- }
11
- }
12
-
13
- return JsonResponse({Buckets: buckets})
14
- }
15
-
@@ -1,24 +0,0 @@
1
- export async function renameObject(request, env, context) {
2
- const body = await request.json()
3
-
4
- const {disk} = request.params
5
- const bucket = env[disk]
6
-
7
- const {path} = body
8
- const {oldName} = body
9
- const {newName} = body
10
-
11
- const object = await bucket.get(`${path}${oldName}`);
12
-
13
- await bucket.put(`${path}${newName}`, object.body);
14
-
15
- await bucket.delete(`${path}${oldName}`);
16
-
17
- const headers = new Headers();
18
- object.writeHttpMetadata(headers);
19
- headers.set('etag', object.httpEtag);
20
-
21
- return new Response(object.body, {
22
- headers,
23
- });
24
- }
@@ -1,23 +0,0 @@
1
- import { JsonResponse } from './core'
2
-
3
- export async function uploadFiles (request, env, context) {
4
- const form = await request.formData()
5
-
6
- const { disk } = request.params
7
- const bucket = env[disk]
8
- const { path } = request.query
9
-
10
- // const path = form.get('path')
11
- const files = form.get('files')
12
-
13
- if (Array.isArray(files)) {
14
- Array.from(files).forEach(async file => {
15
- await bucket.put(`${path}${file.name}`, file);
16
- })
17
- } else {
18
- console.log(files)
19
- await bucket.put(`${path}${files.name}`, files);
20
- }
21
-
22
- return JsonResponse({ status: 'ok' })
23
- }
package/src/index.js DELETED
@@ -1,60 +0,0 @@
1
- import {Router} from 'itty-router';
2
- import {listDisks} from './api/listDisks'
3
- import {listContents} from './api/listContents'
4
- import {uploadFiles} from './api/uploadFiles'
5
- import {createFolder} from './api/createFolder'
6
- import {deleteObject} from './api/deleteObject'
7
- import {renameObject} from './api/renameObject'
8
- import {downloadFile} from './api/downloadFile'
9
- import html from 'explorer:index.html'
10
- import app from 'explorer:js/app.js'
11
- import favicon from 'explorer:favicon.png'
12
-
13
- export function R2Explorer() {
14
- const router = Router();
15
-
16
- router.get('/', () => {
17
- return new Response(atob(html), {
18
- status: 200, headers: {
19
- 'content-type': 'text/html;charset=UTF-8',
20
- }
21
- });
22
- });
23
-
24
- router.get('/js/app.js', () => {
25
- return new Response(atob(app), {
26
- status: 200, headers: {
27
- 'content-type': 'text/js;charset=UTF-8',
28
- }
29
- });
30
- });
31
-
32
- router.get('/favicon.png', () => {
33
- return new Response(atob(favicon), {
34
- status: 200, headers: {
35
- 'content-type': 'image/png',
36
- }
37
- });
38
- });
39
-
40
- router.get('/api/disks', listDisks)
41
- router.get('/api/disks/:disk', listContents)
42
- router.post('/api/disks/:disk/rename', renameObject)
43
- router.post('/api/disks/:disk/folder', createFolder)
44
- router.post('/api/disks/:disk/download-file', downloadFile)
45
- router.post('/api/disks/:disk/upload', uploadFiles)
46
- router.post('/api/disks/:disk/delete', deleteObject)
47
-
48
- router.get('/api/*', (request, env, context) => {
49
- return new Response(JSON.stringify({msg: '404, not found!'}), {
50
- headers: {
51
- 'content-type': 'application/json;charset=UTF-8'
52
- },
53
- status: 404
54
- })
55
- })
56
-
57
- router.all('*', () => new Response('404, not found!', {status: 404}));
58
-
59
- return router
60
- }
package/wrangler.toml DELETED
@@ -1,15 +0,0 @@
1
- name = "r2-explorer"
2
- compatibility_date = "2022-08-09"
3
- main = "dist/index.js"
4
-
5
- [build]
6
- command = "npm install && npm run build"
7
-
8
- [[r2_buckets]]
9
- binding = 'storage'
10
- bucket_name = 'storage'
11
- preview_bucket_name = 'storage'
12
- [[r2_buckets]]
13
- binding = 'teste'
14
- bucket_name = 'teste'
15
- preview_bucket_name = 'teste'