mirror of
https://github.com/jiangrui1994/CloudSaver.git
synced 2026-01-11 15:48:47 +08:00
Refactor the backend
This commit is contained in:
32
backend/src/controllers/BaseCloudController.ts
Normal file
32
backend/src/controllers/BaseCloudController.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { Request, Response } from "express";
|
||||
import { BaseController } from "./BaseController";
|
||||
import { ICloudStorageService } from "@/types/services";
|
||||
|
||||
export abstract class BaseCloudController extends BaseController {
|
||||
constructor(protected cloudService: ICloudStorageService) {
|
||||
super();
|
||||
}
|
||||
|
||||
async getShareInfo(req: Request, res: Response): Promise<void> {
|
||||
await this.handleRequest(req, res, async () => {
|
||||
const { shareCode, receiveCode } = req.query;
|
||||
await this.cloudService.setCookie(req);
|
||||
return await this.cloudService.getShareInfo(shareCode as string, receiveCode as string);
|
||||
});
|
||||
}
|
||||
|
||||
async getFolderList(req: Request, res: Response): Promise<void> {
|
||||
await this.handleRequest(req, res, async () => {
|
||||
const { parentCid } = req.query;
|
||||
await this.cloudService.setCookie(req);
|
||||
return await this.cloudService.getFolderList(parentCid as string);
|
||||
});
|
||||
}
|
||||
|
||||
async saveFile(req: Request, res: Response): Promise<void> {
|
||||
await this.handleRequest(req, res, async () => {
|
||||
await this.cloudService.setCookie(req);
|
||||
return await this.cloudService.saveSharedFile(req.body);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user