feat:版本迭代

This commit is contained in:
jiangrui
2025-02-20 12:00:19 +08:00
parent fd110590af
commit 510fdc48f6
86 changed files with 5045 additions and 1161 deletions

View File

@@ -1,46 +1,61 @@
import { Request, Response, NextFunction } from "express";
import { Cloud115Service } from "../services/Cloud115Service";
import { config } from "../config";
import handleError from "../utils/handleError";
import { handleResponse } from "../utils/responseHandler";
import { sendSuccess, sendError } from "../utils/response";
import UserSetting from "../models/UserSetting";
const { cookie } = config.cloud115;
const cloud115 = new Cloud115Service(cookie);
const cloud115 = new Cloud115Service();
const setCookie = async (req: Request) => {
const userId = req.user?.userId;
const userSetting = await UserSetting.findOne({
where: { userId },
});
console.log(userSetting?.dataValues.cloud115Cookie);
if (userSetting && userSetting.dataValues.cloud115Cookie) {
cloud115.setCookie(userSetting.dataValues.cloud115Cookie);
} else {
throw new Error("请先设置115网盘cookie");
}
};
export const cloud115Controller = {
async getShareInfo(req: Request, res: Response, next: NextFunction) {
try {
const { shareCode, receiveCode } = req.query;
await setCookie(req);
const result = await cloud115.getShareInfo(shareCode as string, receiveCode as string);
handleResponse(res, result, true);
sendSuccess(res, result);
} catch (error) {
handleError(res, error, "获取分享信息失败", next);
console.log(error);
sendError(res, { message: (error as Error).message || "获取分享信息失败" });
}
},
async getFolderList(req: Request, res: Response, next: NextFunction) {
try {
const { parentCid } = req.query;
await setCookie(req);
const result = await cloud115.getFolderList(parentCid as string);
handleResponse(res, result, true);
sendSuccess(res, result);
} catch (error) {
handleError(res, error, "获取目录列表失败", next);
sendError(res, { message: (error as Error).message || "获取目录列表失败" });
}
},
async saveFile(req: Request, res: Response, next: NextFunction) {
try {
const { shareCode, receiveCode, fileId, folderId } = req.body;
await setCookie(req);
const result = await cloud115.saveSharedFile({
shareCode,
receiveCode,
fileId,
cid: folderId,
});
handleResponse(res, result, true);
sendSuccess(res, result);
} catch (error) {
handleError(res, error, "保存文件失败", next);
sendError(res, { message: (error as Error).message || "保存文件失败" });
}
},
};
export const Cloud115ServiceInstance = cloud115;