Skip to content

Commit

Permalink
Merge pull request #442 from sparcs-kaist/dev
Browse files Browse the repository at this point in the history
Main branch update from Dev branch
  • Loading branch information
14KGun authored Jan 2, 2024
2 parents f673b4f + 299052a commit 61b4aff
Show file tree
Hide file tree
Showing 9 changed files with 391 additions and 359 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"test": "npm run sample && cross-env TZ='Asia/Seoul' npm run mocha",
"mocha": "cross-env TZ='Asia/Seoul' NODE_ENV=test mocha --recursive --reporter spec --exit",
"serve": "cross-env TZ='Asia/Seoul' NODE_ENV=production node app.js",
"runscript": "cross-env TZ='Asia/Seoul' NODE_ENV=production node",
"lint": "npx eslint --fix .",
"sample": "cd sampleGenerator && npm start && cd .."
},
Expand Down Expand Up @@ -59,6 +60,7 @@
"eslint": "^8.22.0",
"eslint-plugin-mocha": "^10.1.0",
"mocha": "^10.2.0",
"mongodb": "^6.2.0",
"nodemon": "^3.0.1",
"supertest": "^6.2.4"
}
Expand Down
57 changes: 41 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions scripts/profileImageUrlUpdater.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Issue #173을 해결하기 위한 DB 마이그레이션 스크립트입니다.
// https://github.com/sparcs-kaist/taxi-back/issues/173

const { MongoClient } = require("mongodb");
const { mongo: mongoUrl, aws: awsEnv } = require("../loadenv");

const time = Date.now();

const client = new MongoClient(mongoUrl);
const db = client.db("taxi");
const users = db.collection("users");

async function run() {
try {
for await (const doc of users.find()) {
// 이미 변환이 완료된 경우에는 Pass합니다.
if (doc.profileImageUrl.startsWith(awsEnv.s3Url)) continue;

await users.findOneAndUpdate(
{ _id: doc._id },
{
$set: {
profileImageUrl: `${awsEnv.s3Url}/profile-img/${doc.profileImageUrl}?token=${time}`,
},
}
);
}
} catch (err) {
console.log(err);
} finally {
await client.close();
}
}
run().then(() => {
console.log("Done!");
});
3 changes: 2 additions & 1 deletion src/modules/modifyProfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const crypto = require("crypto");
const aws = require("./stores/aws");

const nouns = [
"재료역학",
Expand Down Expand Up @@ -81,7 +82,7 @@ const generateNickname = (id) => {
// 기존 프로필 사진의 URI 중 하나를 무작위로 선택해 반환합니다.
const generateProfileImageUrl = () => {
const ridx = crypto.randomInt(defaultProfile.length);
return `default/${defaultProfile[ridx]}`;
return aws.getS3Url(`/profile-img/default/${defaultProfile[ridx]}`);
};

// 사용자의 이름과 성을 받아, 한글인지 영어인지에 따라 전체 이름을 반환합니다.
Expand Down
8 changes: 5 additions & 3 deletions src/modules/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,11 @@ const emitUpdateEvent = async (io, roomId) => {
throw new IllegalArgumentsException();
}

part.forEach(({ user }) => io.in(`user-${user}`).emit("chat_update"), {
roomId,
});
part.forEach(({ user }) =>
io.in(`user-${user}`).emit("chat_update", {
roomId,
})
);

return true;
} catch (err) {
Expand Down
Loading

0 comments on commit 61b4aff

Please sign in to comment.