Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix uploadToS3 import path #5472

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/scripts/build/uploadAutoCompleteLocations.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import os from "os";
import path from "path";
import fs from "fs";
import AdmZip from "adm-zip";
import { uploadToS3 } from "../../utils/s3.js";
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note the changed path - but also, @rhelmer, you explicitly made this into a dynamic import here:

https://github.com/mozilla/blurts-server/pull/4949/files#diff-86136336e578d7cf634398ffcbdfaf05b5b938e85866325dad589fb4ff98b191R331

Was that just to avoid importing it if not used? Because I think that potentially obscures the path being invalid, so I changed it to a regular import - but let me know if there's another reason.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC it was to be able to run this locally more easily when setting up a new dev env, I'm fine changing it as long as it works. It was added in #4949


const REMOTE_DATA_URL = "https://download.geonames.org/export/dump";
const DATA_COUNTRY_CODE = "US";
Expand Down Expand Up @@ -328,7 +329,6 @@ try {
if (process.argv.includes("--skip-upload")) {
console.debug("Skipping S3 upload");
} else {
const uploadToS3 = await import("../s3.js");
await uploadToS3(`autocomplete/${LOCATIONS_DATA_FILE}`, readStream);
}

Expand Down
10 changes: 7 additions & 3 deletions src/utils/s3.ts → src/utils/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ const s3 = new S3({
},
});

export async function uploadToS3(fileName: string, fileStream: Buffer) {
/**
* @param {string} fileName
* @param {Buffer} fileStream
*/
export async function uploadToS3(fileName, fileStream) {
console.log("Attempt to upload to s3: ", fileName);
const uploadParams = {
Bucket,
Expand All @@ -37,7 +41,7 @@ export async function uploadToS3(fileName: string, fileStream: Buffer) {
params: uploadParams,
}).done();
console.log("Successfully uploaded data to " + Bucket + "/" + fileName);
} catch (err) {
console.error(err, (err as Error).stack);
} catch (/** @type {any} */ err) {
console.error(err, err.stack);
}
}
Loading