aboutsummaryrefslogtreecommitdiff
path: root/src/server/apis
diff options
context:
space:
mode:
authorSam Wilkins <samwilkins333@gmail.com>2019-09-07 17:08:49 -0400
committerSam Wilkins <samwilkins333@gmail.com>2019-09-07 17:08:49 -0400
commit32cd51e2bcc0a8cf498c0b31a5ead60802f672de (patch)
treee353f730591ee9b7d1a5661364679dc33fe38fa1 /src/server/apis
parentd94509864920b2bbe7f4af8837f3af3f721b7dad (diff)
working on import from google photos
Diffstat (limited to 'src/server/apis')
-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));
});