aboutsummaryrefslogtreecommitdiff
path: root/src/server/apis/google
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/apis/google')
-rw-r--r--src/server/apis/google/GooglePhotosUploadUtils.ts14
1 files changed, 5 insertions, 9 deletions
diff --git a/src/server/apis/google/GooglePhotosUploadUtils.ts b/src/server/apis/google/GooglePhotosUploadUtils.ts
index 13db1df03..032bc2a2d 100644
--- a/src/server/apis/google/GooglePhotosUploadUtils.ts
+++ b/src/server/apis/google/GooglePhotosUploadUtils.ts
@@ -20,6 +20,7 @@ export namespace GooglePhotosUploadUtils {
export interface DownloadInformation {
mediaPath: string;
+ fileName: string;
contentType?: string;
contentSize?: string;
}
@@ -77,15 +78,9 @@ export namespace GooglePhotosUploadUtils {
export namespace IOUtils {
- export const Download = async (url: string): Promise<Opt<DownloadInformation>> => {
- const filename = `temporary_upload_${Utils.GenerateGuid()}${path.extname(url).toLowerCase()}`;
- const temporaryDirectory = Paths.uploadDirectory + "temporary/";
- const mediaPath = temporaryDirectory + filename;
-
- if (!(await createIfNotExists(temporaryDirectory))) {
- return undefined;
- }
-
+ export const Download = async (url: string, filename?: string): Promise<Opt<DownloadInformation>> => {
+ const resolved = filename || `upload_${Utils.GenerateGuid()}${path.extname(url).toLowerCase()}`;
+ const mediaPath = Paths.uploadDirectory + resolved;
return new Promise<DownloadInformation>((resolve, reject) => {
request.head(url, (error, res) => {
if (error) {
@@ -95,6 +90,7 @@ export namespace GooglePhotosUploadUtils {
mediaPath,
contentType: res.headers['content-type'],
contentSize: res.headers['content-length'],
+ fileName: resolved
};
request(url).pipe(fs.createWriteStream(mediaPath)).on('close', () => resolve(information));
});