Skip to content

Commit

Permalink
merge #65
Browse files Browse the repository at this point in the history
  • Loading branch information
abudaan committed May 23, 2024
1 parent af1a4ea commit f3fd389
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
15 changes: 10 additions & 5 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 Expand Up @@ -257,7 +262,7 @@ export class AdapterAzureBlob extends AbstractAdapter {
readStream = fs.createReadStream(f);
} else if (typeof (params as FileBufferParams).buffer !== "undefined") {
readStream = new Readable();
readStream._read = (): void => {}; // _read is required but you can noop it
readStream._read = (): void => { }; // _read is required but you can noop it
readStream.push((params as FileBufferParams).buffer);
readStream.push(null);
} else if (typeof (params as FileStreamParams).stream !== "undefined") {
Expand Down
12 changes: 11 additions & 1 deletion src/AdapterGoogleCloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,17 @@ 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);
return { value: file.publicUrl(), error: null };
if (options.isPublicFile && !options.forceSignedUrl) {
return { value: file.publicUrl(), error: null };
} else {
return {
value: await file.getSignedUrl({
action: 'read',
expires: options.expiresOn || 86400,
})[0],
error: null
}
}
} catch (e) {
return { value: null, error: e.message };
}
Expand Down
11 changes: 9 additions & 2 deletions src/AdapterLocal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class AdapterLocal extends AbstractAdapter {
return { value: dest, error: null };
} else if (typeof (params as FileBufferParams).buffer !== "undefined") {
readStream = new Readable();
readStream._read = (): void => {}; // _read is required but you can noop it
readStream._read = (): void => { }; // _read is required but you can noop it
readStream.push((params as FileBufferParams).buffer);
readStream.push(null);
} else if (typeof (params as FileStreamParams).stream !== "undefined") {
Expand Down Expand Up @@ -209,7 +209,14 @@ export class AdapterLocal extends AbstractAdapter {
): Promise<ResultObject> {
try {
const p = path.join(this._config.directory, bucketName, fileName);
await fs.promises.access(p);
try {
await fs.promises.access(p);
} catch (e) {
return { value: null, error: e }
}
if (options.withoutDirectory) {
return { value: path.join(bucketName, fileName), error: null };
}
return { value: p, error: null };
} catch (e) {
return { value: null, error: e.message };
Expand Down

0 comments on commit f3fd389

Please sign in to comment.