Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try {
const query = ctx.params.id ? { uid: ctx.params.id } : {};
const libraries = await this.service.find(query);
Promise.all(libraries.map(async lib => this.libraryScanner.scan(lib)));
} catch (err) {
console.log('Error occurred while scanning', err);
}
}
}
// Maps routes to method calls on the `api` controller.
// See the `awilix-router-core` docs for info:
// https://github.com/jeffijoe/awilix-router-core
export default createController(LibraryRestApi)
.prefix('/api/libraries')
.get('', 'find')
.get('/:id', 'get')
.post('', 'create')
.patch('/:id', 'update')
.delete('/:id', 'remove')
.post('/:id/scan', 'scan')
.post('/scan', 'scan');
/* eslint-disable no-useless-constructor */
import { createController } from 'awilix-koa';
import StreamApi from './base-stream-api';
class TranscodeApi extends StreamApi {
constructor(movieService, episodeService, ffmpegStreamer) {
super(movieService, episodeService, ffmpegStreamer);
}
getRange(ctx) {
return false;
}
}
export default createController(TranscodeApi)
.prefix('/transcode')
.get('/:type/:id', 'stream');
/* eslint-disable no-useless-constructor */
import { createController } from 'awilix-koa';
import BaseRestApi from './base-api';
class SeasonsRestApi extends BaseRestApi {
constructor(seasonService) {
super(seasonService);
}
}
// Maps routes to method calls on the `api` controller.
// See the `awilix-router-core` docs for info:
// https://github.com/jeffijoe/awilix-router-core
export default createController(SeasonsRestApi)
.prefix('/api/seasons')
.get('', 'find')
.get('/:id', 'get')
.post('', 'create')
.patch('/:id', 'update')
.delete('/:id', 'remove');
/* eslint-disable no-useless-constructor */
import { createController } from 'awilix-koa';
import BaseRestApi from './base-api';
class EpisodeRestApi extends BaseRestApi {
constructor(episodeService) {
super(episodeService);
}
}
// Maps routes to method calls on the `api` controller.
// See the `awilix-router-core` docs for info:
// https://github.com/jeffijoe/awilix-router-core
export default createController(EpisodeRestApi)
.prefix('/api/episodes')
.get('', 'find')
.get('/:id', 'get')
.post('', 'create')
.patch('/:id', 'update')
.delete('/:id', 'remove');
// just over HTTP.
const api = todoService => ({
findTodos: async ctx => ctx.ok(await todoService.find(ctx.query)),
getTodo: async ctx => ctx.ok(await todoService.get(ctx.params.id)),
createTodo: async ctx =>
ctx.created(await todoService.create(ctx.request.body)),
updateTodo: async ctx =>
ctx.ok(await todoService.update(ctx.params.id, ctx.request.body)),
removeTodo: async ctx =>
ctx.noContent(await todoService.remove(ctx.params.id))
})
// Maps routes to method calls on the `api` controller.
// See the `awilix-router-core` docs for info:
// https://github.com/jeffijoe/awilix-router-core
export default createController(api)
.prefix('/todos')
.get('', 'findTodos')
.get('/:id', 'getTodo')
.post('', 'createTodo')
.patch('/:id', 'updateTodo')
.delete('/:id', 'removeTodo')
return ctx.ok(await this.seasonService.find(query));
}
async getEpisodes(ctx) {
let query = { ...{ show_uid: ctx.params.id }, ...ctx.query };
if (ctx.params.sid) {
const seasonIdkey = isNaN(ctx.params.sid) ? 'season_uid' : 'season_number';
query[seasonIdkey] = ctx.params.sid;
}
return ctx.ok(await this.episodeService.find(query));
}
}
export default createController(ShowRestApi)
.prefix('/api/shows')
.get('', 'find')
.get('/:id', 'get')
.get('/:id/seasons', 'getSeasons')
.get('/:id/episodes', 'getEpisodes')
.get('/:id/seasons/:sid', 'getSeasons')
.get('/:id/seasons/:sid/episodes', 'getEpisodes')
.post('', 'create')
.patch('/:id', 'update')
.delete('/:id', 'remove');
// Maps routes to method calls on the `api` controller.
// See the `awilix-router-core` docs for info:
// https://github.com/jeffijoe/awilix-router-core
async stream(ctx, res) {
const session = ctx.query.session;
const segment = ctx.params.segment;
ctx.body = await this.streamer.getStream(segment, session);
}
async stop(ctx, res) {
const session = ctx.query.session;
this.streamer.stopStream(session);
ctx.body = { message: 'ok' };
}
}
export default createController(HlsApi)
.prefix('/hls')
.get('/:type/:id/index.m3u8', 'masterPlaylist')
.get('/:type/:id/video.m3u8', 'playlist')
.get('/:type/:id/index:segment.ts', 'stream')
.post('/:type/:id/stop', 'stop');
* exports a "controller" that `awilix-koa` use for routing.
* 返回路由控制器供`awilix-koa` 使用路由
*/
const api = productService => ({
getProduct: async ctx => ctx.ok(await productService.get(ctx.params.id)),
getList: async ctx => {
ctx.ok(await productService.getList(ctx.request.body))
},
createProduct: async ctx =>
ctx.ok(await productService.create(ctx.request.body)),
})
export default createController(api)
.prefix('/public/products')
.get('/get/:id', 'getProduct')
.post('/create', 'createProduct')
.post('/getlist', 'getList')
import { createController } from 'awilix-koa'
/**
* more info about [`awilix-koa`] (https://github.com/jeffijoe/awilix-koa#awesome-usage)
* more info about [`awilix-router`] (https://github.com/jeffijoe/awilix-router-core)
* exports a "controller" that `awilix-koa` use for routing.
* 返回路由控制器供`awilix-koa` 使用路由
*/
const api = userService => ({
login: async ctx => ctx.ok(await userService.login(ctx.request.body)),
register: async ctx =>
ctx.ok(await userService.register(ctx.request.body)),
})
export default createController(api)
.prefix('/public/user')
.post('/login', 'login')
.post('/logout', 'logout')
.post('/register', 'register')
const api = starService => ({
findStars: async ctx => {
const userId = ctx.state.user.data._id
ctx.ok(await starService.findStars(userId))
},
addStar: async ctx => {
const userId = ctx.state.user.data._id
ctx.ok(await starService.addStar(userId, ctx.request.body))
},
removeStar: async ctx => {
const userId = ctx.state.user.data._id
ctx.ok(await starService.removeStar(userId, ctx.params.id))
}
})
export default createController(api)
.prefix('/star')
.get('/starlist', 'findStars')
.post('/add', 'addStar')
.get('/remove/:id', 'removeStar')