From 4f2a1704c5cdbe7b873aaac1ba07813262693903 Mon Sep 17 00:00:00 2001 From: Ji HyeonSu Date: Sat, 17 Feb 2024 02:27:49 +0900 Subject: [PATCH] [FIX] TOKEN --- index.js | 7 +++---- package-lock.json | 19 ++++++++++++++++--- package.json | 1 + src/controllers/summary.controller.js | 5 +++-- src/routes/progress.route.js | 3 ++- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 32bce85..337e63c 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,7 @@ import cors from 'cors'; import jwt from 'jsonwebtoken'; import cookieParser from 'cookie-parser'; +import { v4 as uuidv4 } from 'uuid'; import { response } from './config/response.js'; import { BaseError } from './config/error.js'; import { status } from './config/response.status.js'; @@ -96,10 +97,8 @@ app.listen(app.get('port'), () => { // 임시 토큰 생성 및 쿠키 저장 미들웨어 function generateTempToken(req, res, next) { // 임시 토큰 생성 (여기서는 간단히 예시를 위한 토큰을 생성합니다) - const tempToken = jwt.sign({ user: 'tempUser' }, process.env.JWT_SECRET); - - // 쿠키에 토큰 저장 - res.cookie('tempToken', tempToken, { httpOnly: true }); + const uniqueId = uuidv4(); // 'uuid' 모듈의 v4 함수를 사용하여 UUID 생성 + const tempToken = jwt.sign({ userId: uniqueId }, process.env.JWT_SECRET); // 토큰 정보를 JSON 형태로 응답 res.status(200).json({ status: 200, success: true, message: '임시토큰이 발행되었습니다.', result: { tempToken }}); diff --git a/package-lock.json b/package-lock.json index 239f369..74ee942 100644 --- a/package-lock.json +++ b/package-lock.json @@ -35,6 +35,7 @@ "swagger-cli": "^4.0.4", "swagger-jsdoc": "^6.2.8", "swagger-ui-express": "^5.0.0", + "uuid": "^9.0.1", "youtube-mp3-downloader": "^0.7.11", "ytdl-core": "^4.11.5" }, @@ -2945,6 +2946,14 @@ "node": ">= 10.0.0" } }, + "node_modules/aws-sdk/node_modules/uuid": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.0.0.tgz", + "integrity": "sha512-jOXGuXZAWdsTH7eZLtyXMqUb9EcWMGZNbL9YcGBJl4MH4nrxHmZJhEHvyLFrkxo+28uLb/NYRcStH48fnD0Vzw==", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/axios": { "version": "1.6.7", "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.7.tgz", @@ -12599,9 +12608,13 @@ } }, "node_modules/uuid": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.0.0.tgz", - "integrity": "sha512-jOXGuXZAWdsTH7eZLtyXMqUb9EcWMGZNbL9YcGBJl4MH4nrxHmZJhEHvyLFrkxo+28uLb/NYRcStH48fnD0Vzw==", + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], "bin": { "uuid": "dist/bin/uuid" } diff --git a/package.json b/package.json index 3efabf1..935553f 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "swagger-cli": "^4.0.4", "swagger-jsdoc": "^6.2.8", "swagger-ui-express": "^5.0.0", + "uuid": "^9.0.1", "youtube-mp3-downloader": "^0.7.11", "ytdl-core": "^4.11.5" }, diff --git a/src/controllers/summary.controller.js b/src/controllers/summary.controller.js index 0311015..632cd79 100644 --- a/src/controllers/summary.controller.js +++ b/src/controllers/summary.controller.js @@ -23,7 +23,7 @@ export const processVideo = async (req, res) => { if(!token) { return res.status(401).send("비정상 접근입니다."); } - + const id =videoId; console.log("id",id); let videoTitle=""; @@ -31,7 +31,8 @@ export const processVideo = async (req, res) => { getYoutubeTitle(videoId,async function(err,title){ videoTitle=title; }) - const clientId = req.query.clientId; + + const clientId = token; // Object Storage에서 해당 MP3 파일이 존재하는지 확인 const mp3Exists = await checkFileExistsInStorage(process.env.OBJECT_STORAGE_BUCKET_NAME, `${videoId}.mp3`); diff --git a/src/routes/progress.route.js b/src/routes/progress.route.js index 6a0c1ba..b5a6339 100644 --- a/src/routes/progress.route.js +++ b/src/routes/progress.route.js @@ -2,11 +2,12 @@ import express from 'express'; import { addClient, sendProgress } from '../services/progress.service.js'; +import { v4 as uuidv4 } from 'uuid'; const progressRoute = express.Router(); router.get('/progress-stream', (req, res) => { - const clientId = req.query.clientId || new Date().toISOString(); + const clientId = req.query.clientId || uuidv4(); res.setHeader('Content-Type', 'text/event-stream'); res.setHeader('Cache-Control', 'no-cache');