-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #294 from caorushizi/dev-web
feat: ✨ web
- Loading branch information
Showing
39 changed files
with
1,777 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,5 @@ dist | |
bin/Logs | ||
release | ||
types | ||
log | ||
bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"watch": ["dist"], | ||
"ext": "js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const API_PREFIX = "/api"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { inject, injectable } from "inversify"; | ||
import { | ||
DownloadItem, | ||
DownloadItemPagination, | ||
DownloadStatus, | ||
Task, | ||
type Controller, | ||
} from "../interfaces.ts"; | ||
import { TYPES } from "../types.ts"; | ||
import FavoriteRepository from "../repository/FavoriteRepository.ts"; | ||
import { get, post } from "../helper/index.ts"; | ||
import Logger from "../vendor/Logger.ts"; | ||
import VideoRepository from "../repository/VideoRepository.ts"; | ||
import { Context } from "koa"; | ||
import ConfigService from "../services/ConfigService.ts"; | ||
import DownloadService from "../services/DownloadService.ts"; | ||
|
||
@injectable() | ||
export default class DownloadController implements Controller { | ||
constructor( | ||
@inject(TYPES.FavoriteRepository) | ||
private readonly favoriteRepository: FavoriteRepository, | ||
@inject(TYPES.Logger) | ||
private readonly logger: Logger, | ||
@inject(TYPES.VideoRepository) | ||
private readonly videoRepository: VideoRepository, | ||
@inject(TYPES.ConfigService) | ||
private readonly store: ConfigService, | ||
@inject(TYPES.DownloadService) | ||
private readonly downloadService: DownloadService, | ||
) {} | ||
|
||
@get("/") | ||
async getFavorites() { | ||
return false; | ||
} | ||
|
||
@post("add-download-item") | ||
async addDownloadItem(ctx: Context) { | ||
const video = ctx.request.body as DownloadItem; | ||
const item = await this.videoRepository.addVideo(video); | ||
return item; | ||
} | ||
|
||
@post("add-download-items") | ||
async addDownloadItems(ctx: Context) { | ||
const videos = ctx.request.body as DownloadItem[]; | ||
const items = await this.videoRepository.addVideos(videos); | ||
return items; | ||
} | ||
|
||
@post("get-download-items") | ||
async getDownloadItems(ctx: Context) { | ||
const pagination = ctx.request.body as DownloadItemPagination; | ||
const videos = await this.videoRepository.findVideos(pagination); | ||
return videos; | ||
} | ||
|
||
@post("start-download") | ||
async startDownload(ctx: Context) { | ||
const { vid } = ctx.request.body as { vid: number }; | ||
// 查找将要下载的视频 | ||
const video = await this.videoRepository.findVideo(vid); | ||
const { name, url, headers, type } = video; | ||
const { local, deleteSegments } = await this.store.getConfig(); | ||
|
||
const task: Task = { | ||
id: vid, | ||
params: { | ||
url, | ||
type, | ||
local, | ||
name, | ||
headers, | ||
deleteSegments, | ||
}, | ||
}; | ||
await this.videoRepository.changeVideoStatus(vid, DownloadStatus.Watting); | ||
this.downloadService.addTask(task); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,39 @@ | ||
import { inject, injectable } from "inversify"; | ||
import { type Controller } from "../interfaces.ts"; | ||
import { TYPES } from "../types.ts"; | ||
import { ConfigParams, TYPES } from "../types.ts"; | ||
import FavoriteRepository from "../repository/FavoriteRepository.ts"; | ||
import { get } from "../helper/decorator.ts"; | ||
import { get, post } from "../helper/index.ts"; | ||
import Logger from "../vendor/Logger.ts"; | ||
import ConfigService from "../services/ConfigService.ts"; | ||
import { Context } from "koa"; | ||
|
||
@injectable() | ||
export default class HomeController implements Controller { | ||
constructor( | ||
@inject(TYPES.FavoriteRepository) | ||
private readonly favoriteRepository: FavoriteRepository, | ||
@inject(TYPES.Logger) | ||
private readonly logger: Logger, | ||
@inject(TYPES.ConfigService) | ||
private readonly config: ConfigService, | ||
) {} | ||
|
||
@get("/") | ||
async getFavorites() { | ||
return false; | ||
} | ||
|
||
@post("get-app-store") | ||
async getAppStore() { | ||
const store = await this.config.getConfig(); | ||
return store; | ||
} | ||
|
||
@post("set-app-store") | ||
async setAppStore(ctx: Context) { | ||
const params = ctx.request.body as ConfigParams; | ||
this.config.setConfig(params); | ||
this.logger.info("set app store"); | ||
return false; | ||
} | ||
} |
Oops, something went wrong.