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
}).unless({
path: [/^\/public/, "/"]
}));
app
// Top middleware is the error handler.
.use(errorHandler)
// Compress all responses.
.use(compress())
// Adds ctx.ok(), ctx.notFound(), etc..
.use(respond())
// Parses request bodies.
.use(bodyParser())
// Creates an Awilix scope per request. Check out the awilix-koa
// docs for details: https://github.com/jeffijoe/awilix-koa
.use(scopePerRequest(container))
// load routes
.use(loadControllers('../routes/*.js', { cwd: __dirname }))
//open database 开启数据库
dbconnect()
// Create http server 开启服务
const server = http.createServer(app.callback())
// Add a `close` event listener 监听应用关闭
server.on('close', () => {
// tear down database connections, etc.
logger.debug('Server closing, bye!')
})
logger.debug('Server created, ready to listen', { scope: 'startup' })
return server
}
// Container is configured with our services and whatnot.
const container = (app.container = configureContainer())
app
// Top middleware is the error handler.
.use(errorHandler)
// Compress all responses.
.use(compress())
// Adds ctx.ok(), ctx.notFound(), etc..
.use(respond())
// Handles CORS.
.use(cors())
// Parses request bodies.
.use(bodyParser())
// Creates an Awilix scope per request. Check out the awilix-koa
// docs for details: https://github.com/jeffijoe/awilix-koa
.use(scopePerRequest(container))
// Create a middleware to add request-specific data to the scope.
.use(registerContext)
// Load routes (API "controllers")
.use(loadControllers('../routes/*.js', { cwd: __dirname }))
// Default handler when nothing stopped the chain.
.use(notFoundHandler)
// Creates a http server ready to listen.
const server = http.createServer(app.callback())
// Add a `close` event listener so we can clean up resources.
server.on('close', () => {
// You should tear down database connections, TCP connections, etc
// here to make sure Jest's watch-mode some process management
// tool does not release resources.
logger.debug('Server closing, bye!')
rootDir: app.container.resolve('imageDestinationFolder')
})
);
let buildFolder = process.env.NODE_ENV !== ' development' ? '/build' : '';
app.use(
serveStatic({
rootPath: '/web',
rootDir: path.join(__dirname, '/../../frontend', buildFolder),
notFoundFile: 'index.html'
})
);
// Creates an Awilix scope per request. Check out the awilix-koa
// docs for details: https://github.com/jeffijoe/awilix-koa
app.use(scopePerRequest(container));
// Load routes (API "controllers")
app.use(loadControllers('../routes/*.js', { cwd: __dirname }));
// Default handler when nothing stopped the chain.
app.use(notFoundHandler);
// Creates a http server ready to listen.
const server = http.createServer(app.callback());
// Add a `close` event listener so we can clean up resources.
server.on('close', () => {
// You should tear down database connections, TCP connections, etc
// here to make sure Jest's watch-mode some process management
// tool does not release resources.
logger.debug('Server closing, bye!');
});
}));
app
// Top middleware is the error handler.
.use(errorHandler)
// Compress all responses.
.use(compress())
// Adds ctx.ok(), ctx.notFound(), etc..
.use(respond())
// Parses request bodies.
.use(bodyParser())
// Creates an Awilix scope per request. Check out the awilix-koa
// docs for details: https://github.com/jeffijoe/awilix-koa
.use(scopePerRequest(container))
// load routes
.use(loadControllers('../routes/*.js', { cwd: __dirname }))
//open database 开启数据库
dbconnect()
// Create http server 开启服务
const server = http.createServer(app.callback())
// Add a `close` event listener 监听应用关闭
server.on('close', () => {
// tear down database connections, etc.
logger.debug('Server closing, bye!')
})
logger.debug('Server created, ready to listen', { scope: 'startup' })
return server
}