@edgestore/server 0.8.0 → 1.0.0-next.1
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/README.md +10 -4
- package/adapters/astro/index.d.ts +1 -1
- package/adapters/astro/index.js +1 -1
- package/adapters/express/index.d.ts +1 -1
- package/adapters/express/index.js +1 -1
- package/adapters/fastify/index.d.ts +1 -1
- package/adapters/fastify/index.js +1 -1
- package/adapters/hono/index.d.ts +1 -1
- package/adapters/hono/index.js +1 -1
- package/adapters/next/app/index.d.ts +1 -1
- package/adapters/next/app/index.js +1 -1
- package/adapters/next/pages/index.d.ts +1 -1
- package/adapters/next/pages/index.js +1 -1
- package/adapters/remix/index.d.ts +1 -1
- package/adapters/remix/index.js +1 -1
- package/adapters/start/index.d.ts +1 -1
- package/adapters/start/index.js +1 -1
- package/core/index.d.ts +1 -1
- package/core/index.js +1 -1
- package/dist/adapters/astro/index.d.ts +8 -13
- package/dist/adapters/astro/index.d.ts.map +1 -1
- package/dist/adapters/astro/index.js +17 -166
- package/dist/adapters/dispatcher.d.ts +30 -0
- package/dist/adapters/dispatcher.d.ts.map +1 -0
- package/dist/adapters/dispatcher.js +172 -0
- package/dist/adapters/express/index.d.ts +8 -13
- package/dist/adapters/express/index.d.ts.map +1 -1
- package/dist/adapters/express/index.js +27 -99
- package/dist/adapters/fastify/index.d.ts +8 -13
- package/dist/adapters/fastify/index.d.ts.map +1 -1
- package/dist/adapters/fastify/index.js +26 -126
- package/dist/adapters/hono/index.d.ts +8 -13
- package/dist/adapters/hono/index.d.ts.map +1 -1
- package/dist/adapters/hono/index.js +17 -126
- package/dist/adapters/imageTypes.js +1 -3
- package/dist/adapters/next/app/index.d.ts +8 -13
- package/dist/adapters/next/app/index.d.ts.map +1 -1
- package/dist/adapters/next/app/index.js +24 -153
- package/dist/adapters/next/pages/index.d.ts +8 -13
- package/dist/adapters/next/pages/index.d.ts.map +1 -1
- package/dist/adapters/next/pages/index.js +37 -100
- package/dist/adapters/remix/index.d.ts +8 -13
- package/dist/adapters/remix/index.d.ts.map +1 -1
- package/dist/adapters/remix/index.js +17 -141
- package/dist/adapters/shared.d.ts +140 -55
- package/dist/adapters/shared.d.ts.map +1 -1
- package/dist/adapters/shared.js +218 -215
- package/dist/adapters/start/index.d.ts +8 -13
- package/dist/adapters/start/index.d.ts.map +1 -1
- package/dist/adapters/start/index.js +17 -174
- package/dist/core/client/bucketClient.d.ts +7 -0
- package/dist/core/client/bucketClient.d.ts.map +1 -0
- package/dist/core/client/bucketClient.js +312 -0
- package/dist/core/client/index.d.ts +119 -140
- package/dist/core/client/index.d.ts.map +1 -1
- package/dist/core/client/index.js +13 -220
- package/dist/core/index.d.ts +21 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +14 -10
- package/dist/core/provider.d.ts +15 -0
- package/dist/core/provider.d.ts.map +1 -0
- package/dist/core/provider.js +25 -0
- package/dist/core/routerRules.d.ts +21 -0
- package/dist/core/routerRules.d.ts.map +1 -0
- package/dist/core/routerRules.js +54 -0
- package/dist/core/validateFile.d.ts +9 -0
- package/dist/core/validateFile.d.ts.map +1 -0
- package/dist/core/validateFile.js +43 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -10
- package/dist/libs/env.d.ts +3 -0
- package/dist/libs/env.d.ts.map +1 -0
- package/dist/libs/env.js +14 -0
- package/dist/libs/errors/EdgeStoreCredentialsError.js +1 -3
- package/dist/libs/logger.d.ts +2 -1
- package/dist/libs/logger.d.ts.map +1 -1
- package/dist/libs/logger.js +5 -9
- package/dist/libs/utils.js +1 -3
- package/dist/providers/azure-blob/index.d.ts +119 -0
- package/dist/providers/azure-blob/index.d.ts.map +1 -0
- package/dist/providers/azure-blob/index.js +166 -0
- package/dist/providers/edgestore/index.d.ts +171 -3
- package/dist/providers/edgestore/index.d.ts.map +1 -1
- package/dist/providers/edgestore/index.js +307 -141
- package/dist/providers/{aws → s3}/index.d.ts +68 -11
- package/dist/providers/s3/index.d.ts.map +1 -0
- package/dist/providers/s3/index.js +146 -0
- package/dist/test-utils/edgestoreSmoke.d.ts +0 -2
- package/dist/test-utils/edgestoreSmoke.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/package.json +58 -56
- package/providers/azure-blob/index.d.ts +1 -0
- package/providers/azure-blob/index.js +1 -0
- package/providers/edgestore/index.d.ts +1 -1
- package/providers/edgestore/index.js +1 -1
- package/providers/s3/index.d.ts +1 -0
- package/providers/s3/index.js +1 -0
- package/src/adapters/astro/index.ts +27 -211
- package/src/adapters/dispatcher.ts +261 -0
- package/src/adapters/express/index.ts +43 -149
- package/src/adapters/fastify/index.ts +43 -191
- package/src/adapters/hono/index.ts +28 -183
- package/src/adapters/next/app/index.ts +37 -201
- package/src/adapters/next/pages/index.ts +55 -156
- package/src/adapters/remix/index.ts +27 -190
- package/src/adapters/shared.ts +249 -274
- package/src/adapters/start/index.ts +28 -200
- package/src/core/client/bucketClient.ts +480 -0
- package/src/core/client/index.ts +300 -428
- package/src/core/index.ts +42 -1
- package/src/core/provider.ts +80 -0
- package/src/core/routerRules.ts +75 -0
- package/src/core/validateFile.ts +50 -0
- package/src/index.ts +10 -0
- package/src/libs/env.ts +16 -0
- package/src/libs/logger.ts +4 -2
- package/src/providers/azure-blob/index.ts +265 -0
- package/src/providers/edgestore/index.ts +426 -154
- package/src/providers/s3/index.ts +289 -0
- package/src/test-utils/edgestoreSmoke.ts +0 -11
- package/src/version.ts +1 -1
- package/dist/adapters/astro/index.mjs +0 -172
- package/dist/adapters/express/index.mjs +0 -108
- package/dist/adapters/fastify/index.mjs +0 -135
- package/dist/adapters/hono/index.mjs +0 -131
- package/dist/adapters/imageTypes.mjs +0 -12
- package/dist/adapters/next/app/index.mjs +0 -163
- package/dist/adapters/next/pages/index.mjs +0 -112
- package/dist/adapters/remix/index.mjs +0 -148
- package/dist/adapters/shared.mjs +0 -471
- package/dist/adapters/start/index.mjs +0 -181
- package/dist/core/client/index.mjs +0 -221
- package/dist/core/index.mjs +0 -2
- package/dist/core/sdk/index.d.ts +0 -282
- package/dist/core/sdk/index.d.ts.map +0 -1
- package/dist/core/sdk/index.js +0 -256
- package/dist/core/sdk/index.mjs +0 -253
- package/dist/index.mjs +0 -1
- package/dist/libs/errors/EdgeStoreCredentialsError.mjs +0 -10
- package/dist/libs/logger.mjs +0 -53
- package/dist/libs/utils.mjs +0 -10
- package/dist/providers/aws/index.d.ts.map +0 -1
- package/dist/providers/aws/index.js +0 -105
- package/dist/providers/aws/index.mjs +0 -103
- package/dist/providers/azure/index.d.ts +0 -39
- package/dist/providers/azure/index.d.ts.map +0 -1
- package/dist/providers/azure/index.js +0 -87
- package/dist/providers/azure/index.mjs +0 -85
- package/dist/providers/edgestore/index.mjs +0 -164
- package/dist/version.js +0 -7
- package/dist/version.mjs +0 -4
- package/providers/aws/index.d.ts +0 -1
- package/providers/aws/index.js +0 -1
- package/providers/azure/index.d.ts +0 -1
- package/providers/azure/index.js +0 -1
- package/src/core/sdk/index.ts +0 -549
- package/src/providers/aws/index.ts +0 -240
- package/src/providers/azure/index.ts +0 -142
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { S3Client, DeleteObjectCommand, PutObjectCommand, HeadObjectCommand } from '@aws-sdk/client-s3';
|
|
2
|
-
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
|
|
3
|
-
import { v4 } from 'uuid';
|
|
4
|
-
import { getEnv } from '../../adapters/shared.mjs';
|
|
5
|
-
|
|
6
|
-
function AWSProvider(options) {
|
|
7
|
-
const { credentials: credentialsFromOptions, accessKeyId = getEnv('ES_AWS_ACCESS_KEY_ID'), secretAccessKey = getEnv('ES_AWS_SECRET_ACCESS_KEY'), region = getEnv('ES_AWS_REGION'), bucketName = getEnv('ES_AWS_BUCKET_NAME'), endpoint = getEnv('ES_AWS_ENDPOINT'), forcePathStyle = getEnv('ES_AWS_FORCE_PATH_STYLE') === 'true', overwritePath } = options ?? {};
|
|
8
|
-
const baseUrl = options?.baseUrl ?? getEnv('EDGE_STORE_BASE_URL') ?? (endpoint ? `${endpoint}/${bucketName}` : `https://${bucketName}.s3.${region}.amazonaws.com`);
|
|
9
|
-
const credentials = credentialsFromOptions ?? (accessKeyId && secretAccessKey ? {
|
|
10
|
-
accessKeyId,
|
|
11
|
-
secretAccessKey
|
|
12
|
-
} : undefined);
|
|
13
|
-
const s3Client = new S3Client({
|
|
14
|
-
region,
|
|
15
|
-
credentials,
|
|
16
|
-
endpoint,
|
|
17
|
-
forcePathStyle
|
|
18
|
-
});
|
|
19
|
-
return {
|
|
20
|
-
name: 'aws',
|
|
21
|
-
async init () {
|
|
22
|
-
return {};
|
|
23
|
-
},
|
|
24
|
-
getBaseUrl () {
|
|
25
|
-
return baseUrl;
|
|
26
|
-
},
|
|
27
|
-
async getFile ({ url }) {
|
|
28
|
-
const path = url.replace(`${baseUrl}/`, '');
|
|
29
|
-
const { ContentLength, LastModified } = await s3Client.send(new HeadObjectCommand({
|
|
30
|
-
Bucket: bucketName,
|
|
31
|
-
Key: path
|
|
32
|
-
}));
|
|
33
|
-
if (!ContentLength || !LastModified) {
|
|
34
|
-
throw new Error('File not found');
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
url,
|
|
38
|
-
metadata: {},
|
|
39
|
-
path: {},
|
|
40
|
-
size: ContentLength,
|
|
41
|
-
uploadedAt: LastModified
|
|
42
|
-
};
|
|
43
|
-
},
|
|
44
|
-
async requestUpload (params) {
|
|
45
|
-
const { bucketName: esBucketName, fileInfo } = params;
|
|
46
|
-
if (!bucketName) {
|
|
47
|
-
throw new Error('S3 bucketName is not configured in AWSProviderOptions.');
|
|
48
|
-
}
|
|
49
|
-
// Default S3 key (accessPath) construction logic
|
|
50
|
-
const pathPrefix = `${esBucketName}${fileInfo.isPublic ? '/_public' : ''}`;
|
|
51
|
-
const extension = fileInfo.extension ? `.${fileInfo.extension.replace('.', '')}` : '';
|
|
52
|
-
const defaultResolvedFileName = fileInfo.fileName ?? `${v4()}${extension}`;
|
|
53
|
-
const defaultFilePathFromMetadata = fileInfo.path.reduce((acc, item)=>{
|
|
54
|
-
return `${acc}/${item.value}`;
|
|
55
|
-
}, '');
|
|
56
|
-
let accessPath = `${pathPrefix}${defaultFilePathFromMetadata}/${defaultResolvedFileName}`;
|
|
57
|
-
if (overwritePath) {
|
|
58
|
-
accessPath = await overwritePath({
|
|
59
|
-
esBucketName,
|
|
60
|
-
fileInfo,
|
|
61
|
-
defaultAccessPath: accessPath
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
accessPath = accessPath.replace(/^\/+/, '');
|
|
65
|
-
const command = new PutObjectCommand({
|
|
66
|
-
Bucket: bucketName,
|
|
67
|
-
Key: accessPath
|
|
68
|
-
});
|
|
69
|
-
const signedUrl = await getSignedUrl(s3Client, command, {
|
|
70
|
-
expiresIn: 60 * 60
|
|
71
|
-
});
|
|
72
|
-
const finalAccessUrl = `${baseUrl}/${accessPath}`;
|
|
73
|
-
return {
|
|
74
|
-
uploadUrl: signedUrl,
|
|
75
|
-
accessUrl: finalAccessUrl
|
|
76
|
-
};
|
|
77
|
-
},
|
|
78
|
-
async requestUploadParts () {
|
|
79
|
-
throw new Error('Not implemented');
|
|
80
|
-
},
|
|
81
|
-
async completeMultipartUpload () {
|
|
82
|
-
throw new Error('Not implemented');
|
|
83
|
-
},
|
|
84
|
-
async confirmUpload () {
|
|
85
|
-
throw new Error('Not implemented');
|
|
86
|
-
},
|
|
87
|
-
async deleteFile ({ url }) {
|
|
88
|
-
if (!bucketName) {
|
|
89
|
-
throw new Error('S3 bucketName is not configured in AWSProviderOptions for deleteFile.');
|
|
90
|
-
}
|
|
91
|
-
const path = url.replace(`${baseUrl}/`, '');
|
|
92
|
-
await s3Client.send(new DeleteObjectCommand({
|
|
93
|
-
Bucket: bucketName,
|
|
94
|
-
Key: path
|
|
95
|
-
}));
|
|
96
|
-
return {
|
|
97
|
-
success: true
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export { AWSProvider };
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { type Provider } from '@edgestore/shared';
|
|
2
|
-
/**
|
|
3
|
-
* Options for the Azure provider. Compatible with Azure Blob Storage and Azurite.
|
|
4
|
-
* Use Azure Storage Explorer for local development with Azurite.
|
|
5
|
-
* @see https://azure.microsoft.com/de-de/products/storage/storage-explorer
|
|
6
|
-
* @category Providers
|
|
7
|
-
* @example
|
|
8
|
-
* AzureProvider({
|
|
9
|
-
* storageAccountName: 'devstoreaccount1',
|
|
10
|
-
* sasToken: 'some-generated-token-from-azure-storage-explorer',
|
|
11
|
-
* containerName: 'some-container-name',
|
|
12
|
-
* customBaseUrl: 'http://localhost:10000/devstoreaccount1',
|
|
13
|
-
* })
|
|
14
|
-
*/
|
|
15
|
-
export type AzureProviderOptions = {
|
|
16
|
-
/**
|
|
17
|
-
* The storage account name for Azure Blob Storage
|
|
18
|
-
* Can also be set via the `ES_AZURE_ACCOUNT_NAME` environment variable.
|
|
19
|
-
*/
|
|
20
|
-
storageAccountName?: string;
|
|
21
|
-
/**
|
|
22
|
-
* SAS token for Azure Blob Storage
|
|
23
|
-
* Can also be set via the `ES_AZURE_SAS_TOKEN` environment variable.
|
|
24
|
-
*/
|
|
25
|
-
sasToken?: string;
|
|
26
|
-
/**
|
|
27
|
-
* Azure Blob Storage container name
|
|
28
|
-
* Can also be set via the `ES_AZURE_CONTAINER_NAME` environment variable.
|
|
29
|
-
*/
|
|
30
|
-
containerName?: string;
|
|
31
|
-
/**
|
|
32
|
-
* Optional base URL for the Azure Blob Storage.
|
|
33
|
-
* Useful for local development with Azurite. For example: `http://localhost:10000/devstoreaccount1`
|
|
34
|
-
* Can also be set via the `ES_AZURE_BASE_URL` environment variable.
|
|
35
|
-
*/
|
|
36
|
-
customBaseUrl?: string;
|
|
37
|
-
};
|
|
38
|
-
export declare function AzureProvider(options?: AzureProviderOptions): Provider;
|
|
39
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/azure/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAIlD;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,wBAAgB,aAAa,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,QAAQ,CAmGtE"}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var storageBlob = require('@azure/storage-blob');
|
|
4
|
-
var uuid = require('uuid');
|
|
5
|
-
var shared = require('../../adapters/shared.js');
|
|
6
|
-
|
|
7
|
-
function AzureProvider(options) {
|
|
8
|
-
const { storageAccountName = shared.getEnv('ES_AZURE_ACCOUNT_NAME'), sasToken = shared.getEnv('ES_AZURE_SAS_TOKEN'), containerName = shared.getEnv('ES_AZURE_CONTAINER_NAME'), customBaseUrl = shared.getEnv('ES_AZURE_BASE_URL') } = options ?? {};
|
|
9
|
-
const baseUrl = customBaseUrl ?? `https://${storageAccountName}.blob.core.windows.net`;
|
|
10
|
-
const blobServiceClient = new storageBlob.BlobServiceClient(`${baseUrl}?${sasToken}`);
|
|
11
|
-
const containerClient = blobServiceClient.getContainerClient(containerName ?? '');
|
|
12
|
-
function getBlobNameFromUrl(url) {
|
|
13
|
-
try {
|
|
14
|
-
const blobUrl = new URL(url);
|
|
15
|
-
const containerUrl = new URL(containerClient.url);
|
|
16
|
-
const containerPath = containerUrl.pathname.replace(/\/$/, '');
|
|
17
|
-
if (blobUrl.origin !== containerUrl.origin) {
|
|
18
|
-
return url;
|
|
19
|
-
}
|
|
20
|
-
if (!blobUrl.pathname.startsWith(`${containerPath}/`)) {
|
|
21
|
-
return url;
|
|
22
|
-
}
|
|
23
|
-
return decodeURIComponent(blobUrl.pathname.slice(containerPath.length + 1));
|
|
24
|
-
} catch {
|
|
25
|
-
return url;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
function getBlobName(params) {
|
|
29
|
-
const { bucketName: esBucketName, fileInfo } = params;
|
|
30
|
-
const extension = fileInfo.extension ? `.${fileInfo.extension.replace('.', '')}` : '';
|
|
31
|
-
const fileName = fileInfo.fileName ?? `${uuid.v4()}${extension}`;
|
|
32
|
-
return [
|
|
33
|
-
esBucketName,
|
|
34
|
-
...fileInfo.isPublic ? [
|
|
35
|
-
'_public'
|
|
36
|
-
] : [],
|
|
37
|
-
...fileInfo.path.map((item)=>item.value),
|
|
38
|
-
fileName
|
|
39
|
-
].join('/');
|
|
40
|
-
}
|
|
41
|
-
return {
|
|
42
|
-
name: 'azure',
|
|
43
|
-
async init () {
|
|
44
|
-
return {};
|
|
45
|
-
},
|
|
46
|
-
getBaseUrl () {
|
|
47
|
-
return baseUrl;
|
|
48
|
-
},
|
|
49
|
-
async getFile ({ url }) {
|
|
50
|
-
const blobClient = containerClient.getBlobClient(getBlobNameFromUrl(url));
|
|
51
|
-
const { contentLength, lastModified } = await blobClient.getProperties();
|
|
52
|
-
return {
|
|
53
|
-
url: url,
|
|
54
|
-
metadata: {},
|
|
55
|
-
path: {},
|
|
56
|
-
size: contentLength ?? 0,
|
|
57
|
-
uploadedAt: lastModified ?? new Date()
|
|
58
|
-
};
|
|
59
|
-
},
|
|
60
|
-
async requestUpload (params) {
|
|
61
|
-
const blobClient = containerClient.getBlobClient(getBlobName(params));
|
|
62
|
-
const url = blobClient.url;
|
|
63
|
-
return {
|
|
64
|
-
uploadUrl: url,
|
|
65
|
-
accessUrl: url
|
|
66
|
-
};
|
|
67
|
-
},
|
|
68
|
-
async requestUploadParts () {
|
|
69
|
-
throw new Error('Not implemented');
|
|
70
|
-
},
|
|
71
|
-
async completeMultipartUpload () {
|
|
72
|
-
throw new Error('Not implemented');
|
|
73
|
-
},
|
|
74
|
-
async confirmUpload () {
|
|
75
|
-
throw new Error('Not implemented');
|
|
76
|
-
},
|
|
77
|
-
async deleteFile ({ url }) {
|
|
78
|
-
const blobClient = containerClient.getBlobClient(getBlobNameFromUrl(url));
|
|
79
|
-
await blobClient.delete();
|
|
80
|
-
return {
|
|
81
|
-
success: true
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
exports.AzureProvider = AzureProvider;
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { BlobServiceClient } from '@azure/storage-blob';
|
|
2
|
-
import { v4 } from 'uuid';
|
|
3
|
-
import { getEnv } from '../../adapters/shared.mjs';
|
|
4
|
-
|
|
5
|
-
function AzureProvider(options) {
|
|
6
|
-
const { storageAccountName = getEnv('ES_AZURE_ACCOUNT_NAME'), sasToken = getEnv('ES_AZURE_SAS_TOKEN'), containerName = getEnv('ES_AZURE_CONTAINER_NAME'), customBaseUrl = getEnv('ES_AZURE_BASE_URL') } = options ?? {};
|
|
7
|
-
const baseUrl = customBaseUrl ?? `https://${storageAccountName}.blob.core.windows.net`;
|
|
8
|
-
const blobServiceClient = new BlobServiceClient(`${baseUrl}?${sasToken}`);
|
|
9
|
-
const containerClient = blobServiceClient.getContainerClient(containerName ?? '');
|
|
10
|
-
function getBlobNameFromUrl(url) {
|
|
11
|
-
try {
|
|
12
|
-
const blobUrl = new URL(url);
|
|
13
|
-
const containerUrl = new URL(containerClient.url);
|
|
14
|
-
const containerPath = containerUrl.pathname.replace(/\/$/, '');
|
|
15
|
-
if (blobUrl.origin !== containerUrl.origin) {
|
|
16
|
-
return url;
|
|
17
|
-
}
|
|
18
|
-
if (!blobUrl.pathname.startsWith(`${containerPath}/`)) {
|
|
19
|
-
return url;
|
|
20
|
-
}
|
|
21
|
-
return decodeURIComponent(blobUrl.pathname.slice(containerPath.length + 1));
|
|
22
|
-
} catch {
|
|
23
|
-
return url;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
function getBlobName(params) {
|
|
27
|
-
const { bucketName: esBucketName, fileInfo } = params;
|
|
28
|
-
const extension = fileInfo.extension ? `.${fileInfo.extension.replace('.', '')}` : '';
|
|
29
|
-
const fileName = fileInfo.fileName ?? `${v4()}${extension}`;
|
|
30
|
-
return [
|
|
31
|
-
esBucketName,
|
|
32
|
-
...fileInfo.isPublic ? [
|
|
33
|
-
'_public'
|
|
34
|
-
] : [],
|
|
35
|
-
...fileInfo.path.map((item)=>item.value),
|
|
36
|
-
fileName
|
|
37
|
-
].join('/');
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
name: 'azure',
|
|
41
|
-
async init () {
|
|
42
|
-
return {};
|
|
43
|
-
},
|
|
44
|
-
getBaseUrl () {
|
|
45
|
-
return baseUrl;
|
|
46
|
-
},
|
|
47
|
-
async getFile ({ url }) {
|
|
48
|
-
const blobClient = containerClient.getBlobClient(getBlobNameFromUrl(url));
|
|
49
|
-
const { contentLength, lastModified } = await blobClient.getProperties();
|
|
50
|
-
return {
|
|
51
|
-
url: url,
|
|
52
|
-
metadata: {},
|
|
53
|
-
path: {},
|
|
54
|
-
size: contentLength ?? 0,
|
|
55
|
-
uploadedAt: lastModified ?? new Date()
|
|
56
|
-
};
|
|
57
|
-
},
|
|
58
|
-
async requestUpload (params) {
|
|
59
|
-
const blobClient = containerClient.getBlobClient(getBlobName(params));
|
|
60
|
-
const url = blobClient.url;
|
|
61
|
-
return {
|
|
62
|
-
uploadUrl: url,
|
|
63
|
-
accessUrl: url
|
|
64
|
-
};
|
|
65
|
-
},
|
|
66
|
-
async requestUploadParts () {
|
|
67
|
-
throw new Error('Not implemented');
|
|
68
|
-
},
|
|
69
|
-
async completeMultipartUpload () {
|
|
70
|
-
throw new Error('Not implemented');
|
|
71
|
-
},
|
|
72
|
-
async confirmUpload () {
|
|
73
|
-
throw new Error('Not implemented');
|
|
74
|
-
},
|
|
75
|
-
async deleteFile ({ url }) {
|
|
76
|
-
const blobClient = containerClient.getBlobClient(getBlobNameFromUrl(url));
|
|
77
|
-
await blobClient.delete();
|
|
78
|
-
return {
|
|
79
|
-
success: true
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export { AzureProvider };
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { EdgeStoreError } from '@edgestore/shared';
|
|
2
|
-
import { getEnv } from '../../adapters/shared.mjs';
|
|
3
|
-
import { initEdgeStoreSdk } from '../../core/sdk/index.mjs';
|
|
4
|
-
import EdgeStoreCredentialsError from '../../libs/errors/EdgeStoreCredentialsError.mjs';
|
|
5
|
-
|
|
6
|
-
const DEFAULT_BASE_URL = 'https://files.edgestore.dev';
|
|
7
|
-
function EdgeStoreProvider(options) {
|
|
8
|
-
const { accessKey = getEnv('EDGE_STORE_ACCESS_KEY') ?? // @ts-expect-error - In Vite/Astro, the env variables are available on `import.meta`.
|
|
9
|
-
import.meta.env?.EDGE_STORE_ACCESS_KEY, secretKey = getEnv('EDGE_STORE_SECRET_KEY') ?? // @ts-expect-error - In Vite/Astro, the env variables are available on `import.meta`.
|
|
10
|
-
import.meta.env?.EDGE_STORE_SECRET_KEY } = options ?? {};
|
|
11
|
-
const baseUrl = getEnv('EDGE_STORE_BASE_URL') ?? DEFAULT_BASE_URL;
|
|
12
|
-
if (!accessKey || !secretKey) {
|
|
13
|
-
throw new EdgeStoreCredentialsError();
|
|
14
|
-
}
|
|
15
|
-
const edgeStoreSdk = initEdgeStoreSdk({
|
|
16
|
-
accessKey,
|
|
17
|
-
secretKey
|
|
18
|
-
});
|
|
19
|
-
return {
|
|
20
|
-
name: 'edgestore',
|
|
21
|
-
init: async ({ ctx, router })=>{
|
|
22
|
-
const token = await edgeStoreSdk.getToken({
|
|
23
|
-
ctx,
|
|
24
|
-
router
|
|
25
|
-
});
|
|
26
|
-
return {
|
|
27
|
-
token
|
|
28
|
-
};
|
|
29
|
-
},
|
|
30
|
-
getBaseUrl () {
|
|
31
|
-
return baseUrl;
|
|
32
|
-
},
|
|
33
|
-
getFile: async ({ url })=>{
|
|
34
|
-
const { uploadedAt, ...rest } = await edgeStoreSdk.getFile({
|
|
35
|
-
url
|
|
36
|
-
});
|
|
37
|
-
return {
|
|
38
|
-
uploadedAt: new Date(uploadedAt),
|
|
39
|
-
...rest
|
|
40
|
-
};
|
|
41
|
-
},
|
|
42
|
-
async requestUpload ({ bucketName, bucketType, fileInfo, autoSignedUrls }) {
|
|
43
|
-
// multipart upload if file is bigger than a certain size
|
|
44
|
-
const MULTIPART_THRESHOLD = 10 * 1024 * 1024; // 10MB
|
|
45
|
-
let partSize = 5 * 1024 * 1024; // 5MB
|
|
46
|
-
if (fileInfo.size > MULTIPART_THRESHOLD) {
|
|
47
|
-
let totalParts = Math.ceil(fileInfo.size / partSize);
|
|
48
|
-
if (totalParts > 1000) {
|
|
49
|
-
// the maximum number of parts is 1000
|
|
50
|
-
totalParts = 1000;
|
|
51
|
-
partSize = Math.ceil(fileInfo.size / totalParts);
|
|
52
|
-
}
|
|
53
|
-
const res = await edgeStoreSdk.requestUpload({
|
|
54
|
-
bucketName,
|
|
55
|
-
bucketType,
|
|
56
|
-
fileInfo,
|
|
57
|
-
autoSignedUrls,
|
|
58
|
-
multipart: {
|
|
59
|
-
parts: Array.from({
|
|
60
|
-
length: totalParts
|
|
61
|
-
}).map((_, index)=>index + 1)
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
const multipart = res.multipart ? {
|
|
65
|
-
key: res.multipart.key,
|
|
66
|
-
uploadId: res.multipart.uploadId,
|
|
67
|
-
parts: res.multipart.parts.map((part)=>({
|
|
68
|
-
partNumber: part.partNumber,
|
|
69
|
-
uploadUrl: part.signedUrl
|
|
70
|
-
})),
|
|
71
|
-
partSize,
|
|
72
|
-
totalParts
|
|
73
|
-
} : undefined;
|
|
74
|
-
if (multipart) {
|
|
75
|
-
return {
|
|
76
|
-
accessUrl: res.accessUrl,
|
|
77
|
-
thumbnailUrl: res.thumbnailUrl,
|
|
78
|
-
...mapSignedUploadAccess(res),
|
|
79
|
-
multipart
|
|
80
|
-
};
|
|
81
|
-
} else if (res.signedUrl) {
|
|
82
|
-
return {
|
|
83
|
-
accessUrl: res.accessUrl,
|
|
84
|
-
uploadUrl: res.signedUrl,
|
|
85
|
-
thumbnailUrl: res.thumbnailUrl,
|
|
86
|
-
...mapSignedUploadAccess(res)
|
|
87
|
-
};
|
|
88
|
-
} else {
|
|
89
|
-
throw new EdgeStoreError({
|
|
90
|
-
message: 'Could not get upload url',
|
|
91
|
-
code: 'SERVER_ERROR'
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
const res = await edgeStoreSdk.requestUpload({
|
|
96
|
-
bucketName,
|
|
97
|
-
bucketType,
|
|
98
|
-
fileInfo,
|
|
99
|
-
autoSignedUrls
|
|
100
|
-
});
|
|
101
|
-
if (res.signedUrl) {
|
|
102
|
-
return {
|
|
103
|
-
accessUrl: res.accessUrl,
|
|
104
|
-
uploadUrl: res.signedUrl,
|
|
105
|
-
thumbnailUrl: res.thumbnailUrl,
|
|
106
|
-
...mapSignedUploadAccess(res)
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
throw new EdgeStoreError({
|
|
110
|
-
message: 'Could not get upload url',
|
|
111
|
-
code: 'SERVER_ERROR'
|
|
112
|
-
});
|
|
113
|
-
},
|
|
114
|
-
requestUploadParts: async ({ multipart, path })=>{
|
|
115
|
-
const res = await edgeStoreSdk.requestUploadParts({
|
|
116
|
-
multipart,
|
|
117
|
-
key: path
|
|
118
|
-
});
|
|
119
|
-
return {
|
|
120
|
-
multipart: {
|
|
121
|
-
uploadId: res.multipart.uploadId,
|
|
122
|
-
parts: res.multipart.parts.map((part)=>({
|
|
123
|
-
partNumber: part.partNumber,
|
|
124
|
-
uploadUrl: part.signedUrl
|
|
125
|
-
}))
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
},
|
|
129
|
-
getSignedUrls: async (params)=>{
|
|
130
|
-
const res = await edgeStoreSdk.getSignedUrls(params);
|
|
131
|
-
return res.map((item)=>({
|
|
132
|
-
...item,
|
|
133
|
-
expiresAt: new Date(item.expiresAt)
|
|
134
|
-
}));
|
|
135
|
-
},
|
|
136
|
-
completeMultipartUpload: async ({ uploadId, key, parts })=>{
|
|
137
|
-
return await edgeStoreSdk.completeMultipartUpload({
|
|
138
|
-
uploadId,
|
|
139
|
-
key,
|
|
140
|
-
parts
|
|
141
|
-
});
|
|
142
|
-
},
|
|
143
|
-
confirmUpload: async ({ url })=>{
|
|
144
|
-
return await edgeStoreSdk.confirmUpload({
|
|
145
|
-
url
|
|
146
|
-
});
|
|
147
|
-
},
|
|
148
|
-
deleteFile: async ({ url })=>{
|
|
149
|
-
return await edgeStoreSdk.deleteFile({
|
|
150
|
-
url
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
function mapSignedUploadAccess(res) {
|
|
156
|
-
return {
|
|
157
|
-
accessSignedUrl: res.accessSignedUrl,
|
|
158
|
-
accessSignedThumbnailUrl: res.accessSignedThumbnailUrl,
|
|
159
|
-
accessSignedUrlExpiresAt: res.accessSignedUrlExpiresAt ? new Date(res.accessSignedUrlExpiresAt) : undefined,
|
|
160
|
-
accessSignedUrlExpiresIn: res.accessSignedUrlExpiresIn
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export { EdgeStoreProvider };
|
package/dist/version.js
DELETED
package/dist/version.mjs
DELETED
package/providers/aws/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '../../dist/providers/aws';
|
package/providers/aws/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('../../dist/providers/aws');
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '../../dist/providers/azure';
|
package/providers/azure/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('../../dist/providers/azure');
|