bruh
This commit is contained in:
parent
dd8f0e14b9
commit
135caf101f
1 changed files with 9 additions and 10 deletions
|
|
@ -19,8 +19,8 @@ function buf2hex(buffer) {
|
||||||
.join('');
|
.join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function signature(key, date, region, service, stringToSign) {
|
async function signature(secretKey, dateStamp, region, service, stringToSign) {
|
||||||
const kDate = await hmac(new TextEncoder().encode('AWS4' + key), new TextEncoder().encode(date));
|
const kDate = await hmac(new TextEncoder().encode('AWS4' + secretKey), new TextEncoder().encode(dateStamp));
|
||||||
const kRegion = await hmac(kDate, new TextEncoder().encode(region));
|
const kRegion = await hmac(kDate, new TextEncoder().encode(region));
|
||||||
const kService = await hmac(kRegion, new TextEncoder().encode(service));
|
const kService = await hmac(kRegion, new TextEncoder().encode(service));
|
||||||
const kSigning = await hmac(kService, new TextEncoder().encode('aws4_request'));
|
const kSigning = await hmac(kService, new TextEncoder().encode('aws4_request'));
|
||||||
|
|
@ -28,13 +28,7 @@ async function signature(key, date, region, service, stringToSign) {
|
||||||
return buf2hex(sig);
|
return buf2hex(sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createSignature(method, path, headers, payloadHash, accessKeyId, secretAccessKey, dateStamp) {
|
async function createSignature(method, path, headers, payloadHash, accessKeyId, secretAccessKey, amzDate, dateStamp) {
|
||||||
const now = new Date();
|
|
||||||
const amzDate = now
|
|
||||||
.toISOString()
|
|
||||||
.replace(/[:-]|\.\d{3}/g, '')
|
|
||||||
.slice(0, 8);
|
|
||||||
const date = amzDate;
|
|
||||||
const region = 'auto';
|
const region = 'auto';
|
||||||
const service = 's3';
|
const service = 's3';
|
||||||
|
|
||||||
|
|
@ -102,7 +96,11 @@ export async function onRequest(context) {
|
||||||
try {
|
try {
|
||||||
const key = `${Date.now()}-${fileName}`;
|
const key = `${Date.now()}-${fileName}`;
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const amzDate = now.toISOString().replace(/[:-]/g, '').slice(0, 15) + 'Z';
|
const amzDate =
|
||||||
|
now
|
||||||
|
.toISOString()
|
||||||
|
.replace(/[:-]|\.\d{3}/g, '')
|
||||||
|
.slice(0, 15) + 'Z';
|
||||||
const dateStamp = now
|
const dateStamp = now
|
||||||
.toISOString()
|
.toISOString()
|
||||||
.replace(/[:-]|\.\d{3}/g, '')
|
.replace(/[:-]|\.\d{3}/g, '')
|
||||||
|
|
@ -125,6 +123,7 @@ export async function onRequest(context) {
|
||||||
payloadHash,
|
payloadHash,
|
||||||
env.R2_ACCESS_KEY_ID,
|
env.R2_ACCESS_KEY_ID,
|
||||||
env.R2_SECRET_ACCESS_KEY,
|
env.R2_SECRET_ACCESS_KEY,
|
||||||
|
amzDate,
|
||||||
dateStamp
|
dateStamp
|
||||||
);
|
);
|
||||||
headers['Authorization'] = auth;
|
headers['Authorization'] = auth;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue