All checks were successful
CI / container-job (push) Successful in 49s
- Modified Api/Authors.Controller.ts to use only personal types and sort by dataset_count. - Completely rewritten AvatarController.ts. - Added new Api/CollectionsController.ts for querying collections and collection_roles. - Modified Api/DatasetController.ts to preload titles, identifier and order by server_date_published. - Modified FileController.ts to serve files from /storage/app/data/ instead of /storage/app/public. - Added new Api/UserController for requesting submitters (getSubmitters). - Improved OaiController.ts with performant DB queries for better ResumptionToken handling. - Modified Submitter/DatasetController.ts by adding a categorize method for library classification. - Rewritten ResumptionToken.ts. - Improved TokenWorkerService.ts to utilize browser fingerprint. - Edited dataset.ts by adding the doiIdentifier property. - Enhanced person.ts to improve the fullName property. - Completely rewritten AsideMenuItem.vue component. - Updated CarBoxClient.vue to use TypeScript. - Added new CardBoxDataset.vue for displaying recent datasets on the dashboard. - Completely rewritten TableSampleClients.vue for the dashboard. - Completely rewritten UserAvatar.vue. - Made small layout changes in Dashboard.vue. - Added new Category.vue for browsing scientific collections. - Adapted the pinia store in main.ts. - Added additional routes in start/routes.ts and start/api/routes.ts. - Improved referenceValidation.ts for better ISBN existence checking. - NPM dependency updates.
54 lines
2.3 KiB
TypeScript
54 lines
2.3 KiB
TypeScript
import type { HttpContext } from '@adonisjs/core/http';
|
|
import File from '#models/file';
|
|
import { StatusCodes } from 'http-status-codes';
|
|
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
|
|
// node ace make:controller Author
|
|
export default class FileController {
|
|
// @Get("download/:id")
|
|
public async findOne({ response, params }: HttpContext) {
|
|
const id = params.id;
|
|
const file = await File.findOrFail(id);
|
|
// const file = await File.findOne({
|
|
// where: { id: id },
|
|
// });
|
|
if (file) {
|
|
const filePath = '/storage/app/data/' + file.pathName;
|
|
const ext = path.extname(filePath);
|
|
const fileName = file.label + ext;
|
|
try {
|
|
fs.accessSync(filePath, fs.constants.R_OK); //| fs.constants.W_OK);
|
|
// console.log("can read/write:", path);
|
|
|
|
response
|
|
.header('Cache-Control', 'no-cache private')
|
|
.header('Content-Description', 'File Transfer')
|
|
.header('Content-Type', file.mimeType)
|
|
.header('Content-Disposition', 'inline; filename=' + fileName)
|
|
.header('Content-Transfer-Encoding', 'binary')
|
|
.header('Access-Control-Allow-Origin', '*')
|
|
.header('Access-Control-Allow-Methods', 'GET,POST');
|
|
|
|
response.status(StatusCodes.OK).download(filePath);
|
|
} catch (err) {
|
|
// console.log("no access:", path);
|
|
response.status(StatusCodes.NOT_FOUND).send({
|
|
message: `File with id ${id} doesn't exist on file server`,
|
|
});
|
|
}
|
|
|
|
// res.status(StatusCodes.OK).sendFile(filePath, (err) => {
|
|
// // res.setHeader("Content-Type", "application/json");
|
|
// // res.removeHeader("Content-Disposition");
|
|
// res.status(StatusCodes.NOT_FOUND).send({
|
|
// message: `File with id ${id} doesn't exist on file server`,
|
|
// });
|
|
// });
|
|
} else {
|
|
response.status(StatusCodes.NOT_FOUND).send({
|
|
message: `Cannot find File with id=${id}.`,
|
|
});
|
|
}
|
|
}
|
|
}
|