diff --git a/api/controllers/IndexController.ts b/api/controllers/IndexController.ts index 7166bb6..fd4911f 100644 --- a/api/controllers/IndexController.ts +++ b/api/controllers/IndexController.ts @@ -1,16 +1,16 @@ -declare var Job, Asset, Task, Account; +declare var Job, Input, Task, Account; module.exports = { 'index': (req, res) => { - let JobsCount, AssetsCount, TasksCount, AccountsCount; + let JobsCount, InputsCount, TasksCount, AccountsCount; Job.count() .then((val) => { JobsCount = val; - return Asset.count(); + return Input.count(); }) .then((val) => { - AssetsCount = val; + InputsCount = val; return Task.count(); }) .then((val) => { @@ -22,7 +22,7 @@ module.exports = { res.json({ serverStatus: 'online', JobsCount, - AssetsCount, + InputsCount, TasksCount, AccountsCount }); diff --git a/api/controllers/AssetController.ts b/api/controllers/InputController.ts similarity index 69% rename from api/controllers/AssetController.ts rename to api/controllers/InputController.ts index 65d3b96..c906fba 100644 --- a/api/controllers/AssetController.ts +++ b/api/controllers/InputController.ts @@ -1,21 +1,21 @@ /** - * AssetController + * InputController * - * @description :: Server-side logic for managing assets + * @description :: Server-side logic for managing Inputs * @help :: See http://sailsjs.org/#!/documentation/concepts/Controllers */ import { Model } from 'sails-typings'; -declare var Asset: Model; +declare var Input: Model; declare var sails; const path = require('path'); module.exports = { 'uploadFile': (req, res) => { - const dirname = path.resolve(sails.config.appPath, 'assets/assets'); + const dirname = path.resolve(sails.config.appPath, 'assets/inputs'); req.file('asset').upload({ dirname }, function (err, uploadedFiles) { if (err) return res.serverError(err); - Asset.create({ + Input.create({ sourceLanguage: req.param('sourceLanguage'), encoding: req.param('encoding'), jobId: req.param('parentid'), @@ -29,19 +29,19 @@ module.exports = { }, 'downloadFile': (req, res) => { - Asset.findOne(req.param('id')).exec(function (err, asset) { + Input.findOne(req.param('id')).exec(function (err, input) { if (err) return res.serverError(err); - if (!asset) return res.notFound(); - if (!asset.fileDescriptor) return res.notFound(); + if (!input) return res.notFound(); + if (!input.fileDescriptor) return res.notFound(); const SkipperDisk = require('skipper-disk'); const fileAdapter = SkipperDisk(); // set the filename to the same file as the user uploaded - res.set("Content-disposition", "attachment; filename=" + asset.fileOriginalName + ""); + res.set("Content-disposition", "attachment; filename=" + input.fileOriginalName + ""); // Stream the file down - fileAdapter.read(asset.fileDescriptor) + fileAdapter.read(input.fileDescriptor) .on('error', function (err) { return res.serverError(err); }) diff --git a/api/models/Asset.ts b/api/models/Input.ts similarity index 96% rename from api/models/Asset.ts rename to api/models/Input.ts index 7725c60..fce1cb3 100644 --- a/api/models/Asset.ts +++ b/api/models/Input.ts @@ -1,5 +1,5 @@ /** - * Asset.js + * Input.js * * @description :: TODO: You might write a short summary of how this model works and what it represents here. * @docs :: http://sailsjs.org/documentation/concepts/models-and-orm/models @@ -41,7 +41,7 @@ module.exports = { tasks: { collection: 'task', - via: 'assetId' + via: 'inputId' } }, diff --git a/api/models/Job.ts b/api/models/Job.ts index e28f885..4ac2b21 100644 --- a/api/models/Job.ts +++ b/api/models/Job.ts @@ -36,8 +36,8 @@ module.exports = { required: true }, - assets: { - collection: 'asset', + inputs: { + collection: 'input', via: 'jobId' }, diff --git a/api/models/Task.ts b/api/models/Task.ts index 4a52cd3..d54e64e 100644 --- a/api/models/Task.ts +++ b/api/models/Task.ts @@ -48,8 +48,8 @@ export = { required: true }, - assetId: { - model: 'asset' + inputId: { + model: 'input' } } diff --git a/api/models/Webhook.ts b/api/models/Webhook.ts index 25b9fc2..7d7625f 100644 --- a/api/models/Webhook.ts +++ b/api/models/Webhook.ts @@ -37,9 +37,9 @@ module.exports = { 'jobCreated', 'jobUpdated', 'jobDeleted', - 'assetCreated', - 'assetUpdated', - 'assetDeleted' + 'inputCreated', + 'inputUpdated', + 'inputDeleted' ], required: true } diff --git a/config/routes.js b/config/routes.js index edbe353..12d3ae8 100644 --- a/config/routes.js +++ b/config/routes.js @@ -70,30 +70,30 @@ module.exports.routes = { action: 'update' }, - 'DELETE /jobs/:parentid/assets/:id': { - controller: 'AssetController', + 'DELETE /jobs/:parentid/inputs/:id': { + controller: 'InputController', action: 'destroy' }, - 'GET /jobs/:parentid/assets/:id': { - controller: 'AssetController', + 'GET /jobs/:parentid/inputs/:id': { + controller: 'InputController', action: 'findOne' }, - 'PUT /jobs/:parentid/assets/:id': { - controller: 'AssetController', + 'PUT /jobs/:parentid/inputs/:id': { + controller: 'InputController', action: 'update' }, - 'GET /jobs/:parentid/assets': { - controller: 'AssetController', + 'GET /jobs/:parentid/inputs': { + controller: 'InputController', action: 'find' }, - 'POST /jobs/:parentid/assets/uploadfile': + 'POST /jobs/:parentid/inputs/uploadfile': { - controller: 'AssetController', + controller: 'InputController', action: 'uploadFile' }, - 'GET /jobs/:parentid/assets/:id/downloadfile': { - controller: 'AssetController', + 'GET /jobs/:parentid/inputs/:id/downloadfile': { + controller: 'InputController', action: 'downloadFile' }, @@ -128,9 +128,9 @@ module.exports.routes = { action: 'downloadFile' }, - // asset - 'GET /assets': { - controller: 'AssetController', + // input + 'GET /inputs': { + controller: 'InputController', action: 'find' }, diff --git a/test/fixtures/testAssetFile.txt b/test/fixtures/testInputFile.txt similarity index 100% rename from test/fixtures/testAssetFile.txt rename to test/fixtures/testInputFile.txt diff --git a/test/integration/controllers/AssetController.test.js b/test/integration/controllers/InputController.test.js similarity index 77% rename from test/integration/controllers/AssetController.test.js rename to test/integration/controllers/InputController.test.js index fd46a4e..16fe4bb 100644 --- a/test/integration/controllers/AssetController.test.js +++ b/test/integration/controllers/InputController.test.js @@ -4,9 +4,9 @@ var _ = require('lodash'); var constants = require('../../../constants'); var createLocalHostAccount = require('../../../functions').createLocalHostAccount; -describe('AssetController', function () { +describe('InputController', function () { - describe('POST /jobs/:parentid/assets/uploadfile', function () { + describe('POST /jobs/:parentid/inputs/uploadfile', function () { beforeEach(function (done) { const cb = () => Job.create({ id: 1, @@ -21,13 +21,13 @@ describe('AssetController', function () { sails.emit('hook:orm:reload'); }); - it('should handle file upload and asset creation', function (done) { + it('should handle file upload and input creation', function (done) { request(sails.hooks.http.app) - .post('/jobs/1/assets/uploadfile') + .post('/jobs/1/inputs/uploadfile') .set('Authorization', 'Bearer ' + constants.ROOT_USER_API_KEY) .field('sourceLanguage', 'en') .field('encoding', 'utf8') - .attach('asset', 'test/fixtures/testAssetFile.txt') + .attach('input', 'test/fixtures/testInputFile.txt') .expect(200) .then((response) => { expect(_.omit(response.body, ['updatedAt', 'createdAt'])).toEqual({ @@ -36,16 +36,16 @@ describe('AssetController', function () { sourceLanguage: 'en', encoding: 'utf8', fileDescriptor: response.body.fileDescriptor, - fileOriginalName: 'testAssetFile.txt' + fileOriginalName: 'testInputFile.txt' }); - Job.findOne(1).populate('assets').exec(function (err, res) { + Job.findOne(1).populate('inputs').exec(function (err, res) { expect(err).toBe(null) expect(_.omit(res.toJSON(), ['createdAt', 'updatedAt'])).toEqual({ id: 1, name: 'first job', submitter: 'symfonie.com/123', - assets: [response.body] + inputs: [response.body] }); done() }); diff --git a/test/integration/controllers/TaskController.test.js b/test/integration/controllers/TaskController.test.js index e73059e..cd9c100 100644 --- a/test/integration/controllers/TaskController.test.js +++ b/test/integration/controllers/TaskController.test.js @@ -11,14 +11,14 @@ describe('TaskController', function () { name: 'first job', submitter: 'symfonie.com/123' }], - assets: [{ + inputs: [{ id: 1, jobId: 1 }], tasks: [{ id: 1, jobId: 1, - assetId: 1, + inputId: 1, progress: 'pending', type: 'translation' }] @@ -26,7 +26,7 @@ describe('TaskController', function () { describe('POST /tasks/:id/uploaddeliverable', function () { beforeEach(function (done) { const cb = () => Job.create(fixtures.jobs[0]).then(() => { - return Asset.create(fixtures.assets[0]) + return Input.create(fixtures.inputs[0]) }).then(() => { return Task.create(fixtures.tasks[0]) }).then(() => { @@ -46,18 +46,18 @@ describe('TaskController', function () { .attach('deliverable', 'test/fixtures/testDeliverableFile.txt') .expect(200) .then((response) => { - Asset.findOne(fixtures.assets[0].id).populate('tasks').exec(function (err, res) { - const asset = res.toJSON(); - const expectedTask = _.merge(fixtures.tasks[0], _.pick(asset.tasks[0], ['createdAt', 'updatedAt'])); - expectedTask.fileDescriptor = asset.tasks[0].fileDescriptor; + Input.findOne(fixtures.inputs[0].id).populate('tasks').exec(function (err, res) { + const input = res.toJSON(); + const expectedTask = _.merge(fixtures.tasks[0], _.pick(input.tasks[0], ['createdAt', 'updatedAt'])); + expectedTask.fileDescriptor = input.tasks[0].fileDescriptor; expectedTask.fileOriginalName = 'testDeliverableFile.txt'; expectedTask.progress = 'finished'; expect(err).toBe(null) - expect(asset).toEqual({ + expect(input).toEqual({ id: 1, jobId: 1, - createdAt: asset.createdAt, - updatedAt: asset.updatedAt, + createdAt: input.createdAt, + updatedAt: input.updatedAt, tasks: [expectedTask] }); done()