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

Main branch update from Dev branch #442

Merged
merged 17 commits into from
Jan 2, 2024
Merged
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: 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
Loading