@@ -20,7 +20,7 @@ function parseRange(
20
20
21
21
function objectNotFound ( objectName : string ) : Response {
22
22
return new Response (
23
- `<html><body> R2 object "<b>${ objectName } </b>" not found</body></html>` ,
23
+ `<html><body style="background-color:black; color:white"><h3 style="text-align:center"> R2 object "<b>${ objectName } </b>" not found</h3> </body></html>` ,
24
24
{
25
25
status : 404 ,
26
26
headers : {
@@ -51,7 +51,7 @@ export default {
51
51
} ;
52
52
console . log ( JSON . stringify ( options ) ) ;
53
53
54
- const listing = await env . R2_BUCKET . list ( options ) ;
54
+ const listing = await env . R2_STORE . list ( options ) ;
55
55
return new Response ( JSON . stringify ( listing ) , {
56
56
headers : {
57
57
"content-type" : "application/json; charset=UTF-8" ,
@@ -61,7 +61,7 @@ export default {
61
61
62
62
if ( request . method === "GET" ) {
63
63
const range = parseRange ( request . headers . get ( "range" ) ) ;
64
- const object = await env . R2_BUCKET . get ( objectName , {
64
+ const object = await env . R2_STORE . get ( objectName , {
65
65
range,
66
66
onlyIf : request . headers ,
67
67
} ) ;
@@ -73,14 +73,20 @@ export default {
73
73
const headers = new Headers ( ) ;
74
74
object . writeHttpMetadata ( headers ) ;
75
75
headers . set ( "etag" , object . httpEtag ) ;
76
+ /** headers.append("Access-Control-Allow-Headers", "Content-Type, Set-Cookie, Cache-Control");
77
+ headers.append("Access-Control-Allow-Methods", "GET, HEAD, POST, PUT, DELETE, OPTIONS");
78
+ headers.append("Access-Control-Allow-Origin", "htt");
79
+ headers.append("Access-Control-Max-Age", "600");
80
+ headers.append("Vary", "Origin, Accept-Encoding"); */
81
+
76
82
const status = object . body ? ( range ? 206 : 200 ) : 304 ;
77
83
return new Response ( object . body , {
78
84
headers,
79
85
status,
80
86
} ) ;
81
87
}
82
88
83
- const object = await env . R2_BUCKET . head ( objectName ) ;
89
+ const object = await env . R2_STORE . head ( objectName ) ;
84
90
85
91
if ( object === null ) {
86
92
return objectNotFound ( objectName ) ;
@@ -89,14 +95,14 @@ export default {
89
95
const headers = new Headers ( ) ;
90
96
object . writeHttpMetadata ( headers ) ;
91
97
headers . set ( "etag" , object . httpEtag ) ;
92
- headers . append ( "Access-Control-Allow-Origin" , "https://wiki.zshell.dev" ) ;
93
-
94
98
return new Response ( null , {
95
99
headers,
96
100
} ) ;
97
101
}
102
+
103
+ /**
98
104
if (request.method === "PUT" || request.method == "POST") {
99
- const object = await env . R2_BUCKET . put ( objectName , request . body , {
105
+ const object = await env.R2_STORE .put(objectName, request.body, {
100
106
httpMetadata: request.headers,
101
107
});
102
108
return new Response(null, {
@@ -106,10 +112,10 @@ export default {
106
112
});
107
113
}
108
114
if (request.method === "DELETE") {
109
- await env . R2_BUCKET . delete ( url . pathname . slice ( 1 ) ) ;
115
+ await env.R2_STORE .delete(url.pathname.slice(1));
110
116
return new Response();
111
117
}
112
-
118
+ */
113
119
return new Response ( `Unsupported method` , {
114
120
status : 400 ,
115
121
} ) ;
0 commit comments