Skip to content

Commit 594df9f

Browse files
committed
refactor: 쿠키 데이터 가져오는 방식 수정
1 parent 0fcf99b commit 594df9f

3 files changed

Lines changed: 4 additions & 12 deletions

File tree

src/controllers/videoController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const uploadVideoRequests = async (req, res, next) => {
88
const { youtubeUrl } = req.body;
99

1010
try {
11-
const videoStream = await getYoutubeVideo(youtubeUrl);
11+
const videoStream = await getYoutubeVideo(youtubeUrl, req.agent);
1212
const fileName = `${env.ORIGINAL_PREFIX}/${req.videoId}`;
1313

1414
await saveVideoToGcs(videoStream, fileName);

src/routes/middleware/validation/uploadValidation.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import fs from "fs";
2-
31
import ytdl from "@distube/ytdl-core";
42
import createError from "http-errors";
53

64
import { MESSAGES, REQUIRED_FIELDS } from "../../../config/constants.js";
7-
import env from "../../../config/env.js";
85
import { validateReqBody, validateFields } from "../../../utils/validation.js";
96

107
const validateMetadata = (metaData) => {
@@ -33,13 +30,13 @@ const validateUploadUrl = async (req, res, next) => {
3330
throw error;
3431
}
3532

36-
const cookieJson = JSON.parse(fs.readFileSync(env.cookieJson, "utf8"));
33+
const cookieJson = JSON.parse(process.env.COOKIE_DATA);
3734
const cookies = cookieJson.map(({ name, value }) => ({ name, value }));
3835
const agent = ytdl.createAgent(cookies);
3936
const videoInfo = await ytdl.getBasicInfo(youtubeUrl, { agent });
4037

4138
validateMetadata(videoInfo.videoDetails);
42-
39+
req.agent = agent;
4340
next();
4441
} catch (error) {
4542
if (

src/services/videoService.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
import fs from "fs";
21
import { pipeline } from "stream/promises";
32

43
import ytdl from "@distube/ytdl-core";
54
import createError from "http-errors";
65

76
import { MESSAGES } from "../config/constants.js";
8-
import env from "../config/env.js";
97
import { bucket } from "../config/gcs.js";
108

11-
const getYoutubeVideo = async (youtubeUrl) => {
12-
const cookieJson = JSON.parse(fs.readFileSync(env.cookieJson, "utf8"));
13-
const cookies = cookieJson.map(({ name, value }) => ({ name, value }));
14-
const agent = ytdl.createAgent(cookies);
9+
const getYoutubeVideo = async (youtubeUrl, agent) => {
1510
const videoStream = ytdl(youtubeUrl, {
1611
quality: "highestvideo",
1712
agent,

0 commit comments

Comments
 (0)