Skip to content

Commit

Permalink
Merge pull request #61 from jakeFeldman/fix-typescript-migration
Browse files Browse the repository at this point in the history
fix typescript migration
  • Loading branch information
jakeFeldman authored Feb 8, 2023
2 parents 3bbefa2 + 6b2ba09 commit cbf174e
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,38 +45,40 @@ const uploadOptions = {
maxBuffers: 20,
};

function handleUpload(config: Config, blobSvcClient: BlobServiceClient, file: StrapiFile) {
return async () => {
const serviceBaseURL = getServiceBaseUrl(config);
const containerClient = blobSvcClient.getContainerClient(trimParam(config.containerName));
const client = containerClient.getBlockBlobClient(
`${trimParam(config.defaultPath)}/${file.hash}`
);
const options = {
blobHTTPHeaders: { blobContentType: file.mime },
};
async function handleUpload(
config: Config,
blobSvcClient: BlobServiceClient,
file: StrapiFile
): Promise<void> {
const serviceBaseURL = getServiceBaseUrl(config);
const containerClient = blobSvcClient.getContainerClient(trimParam(config.containerName));
const client = containerClient.getBlockBlobClient(
`${trimParam(config.defaultPath)}/${file.hash}`
);
const options = {
blobHTTPHeaders: { blobContentType: file.mime },
};

const cdnBaseURL = trimParam(config.cdnBaseURL);
file.url = cdnBaseURL ? client.url.replace(serviceBaseURL, cdnBaseURL) : client.url;
const cdnBaseURL = trimParam(config.cdnBaseURL);
file.url = cdnBaseURL ? client.url.replace(serviceBaseURL, cdnBaseURL) : client.url;

await client.uploadStream(
file.stream,
uploadOptions.bufferSize,
uploadOptions.maxBuffers,
options
);
};
await client.uploadStream(
file.stream,
uploadOptions.bufferSize,
uploadOptions.maxBuffers,
options
);
}

function handleDelete(config: Config, blobSvcClient: BlobServiceClient, file: StrapiFile) {
return async () => {
const containerClient = blobSvcClient.getContainerClient(trimParam(config.containerName));
const client = containerClient.getBlobClient(
`${trimParam(config.defaultPath)}/${file.hash}`
);
await client.delete();
file.url = client.url;
};
async function handleDelete(
config: Config,
blobSvcClient: BlobServiceClient,
file: StrapiFile
): Promise<void> {
const containerClient = blobSvcClient.getContainerClient(trimParam(config.containerName));
const client = containerClient.getBlobClient(`${trimParam(config.defaultPath)}/${file.hash}`);
await client.delete();
file.url = client.url;
}

module.exports = {
Expand Down

0 comments on commit cbf174e

Please sign in to comment.