Skip to content

Commit

Permalink
* fix options parameter use in getFileAsUrl function on Azure and GCS…
Browse files Browse the repository at this point in the history
… adapters, + add option parameter to fetch public or signed url for azure and gcs adapters
  • Loading branch information
tesirm99 committed May 21, 2024
1 parent 3cb7441 commit a2a1043
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/AdapterAzureBlob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,16 @@ export class AdapterAzureBlob extends AbstractAdapter {
}

try {
const options: BlobGenerateSasUrlOptions = {
permissions: BlobSASPermissions.parse("r"),
expiresOn: new Date(new Date().valueOf() + 86400),
const sasOptions: BlobGenerateSasUrlOptions = {
permissions: options.permissions || BlobSASPermissions.parse("r"),
expiresOn: options.expiresOn || new Date(new Date().valueOf() + 86400),
};
const url = await file.generateSasUrl(options);
let url: string;
if(options.isPublicFile && !options.forceSignedUrl) {
url = file.url;
} else {
url = await file.generateSasUrl(sasOptions);
}
return { value: url, error: null };
} catch (e) {
return { value: null, error: e.message };
Expand Down
8 changes: 4 additions & 4 deletions src/AdapterGoogleCloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ export class AdapterGoogleCloud extends AbstractAdapter {
protected async _getFileAsURL(bucketName: string, fileName: string, options?: Options): Promise<ResultObject> {
try {
const file = this._client.bucket(bucketName).file(fileName);
if(options.signed) {
if(options.isPublicFile && !options.forceSignedUrl) {
return { value: file.publicUrl(), error: null };
} else {
return {
value: await file.getSignedUrl({
action: 'read',
expires: options.expiresIn || 1000 * 60 * 60 * 24,
expires: options.expiresOn || 86400,
})[0],
error: null
}
} else {
return { value: file.publicUrl(), error: null };
}
} catch (e) {
return { value: null, error: e.message };
Expand Down

0 comments on commit a2a1043

Please sign in to comment.