🐛 #23 Fix throw error when file doesn't exist
* #23 Fix throw error when file doesn't exist Run all the tests in once without special runner Add positive scenario Move coverage to the backend build workflow
This commit is contained in:
+1
-2
@@ -44,14 +44,13 @@ export class MongoConnector extends AbstractConnector<MongoConnectionOptions, mo
|
||||
|
||||
async getDatabase(): Promise<mongo.Db> {
|
||||
await this.connect();
|
||||
|
||||
return this.client.db(this.options.database);
|
||||
}
|
||||
|
||||
async drop(): Promise<this> {
|
||||
const db = await this.getDatabase();
|
||||
|
||||
db.dropDatabase();
|
||||
await db.dropDatabase();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { createWriteStream, createReadStream, existsSync, mkdirSync, statSync, r
|
||||
import p from "path";
|
||||
import { rm } from "fs/promises"; // Do not change the import, this is not the same function import { rm } from "fs"
|
||||
import { StorageConnectorAPI, WriteMetadata } from "../../provider";
|
||||
import fs from "fs";
|
||||
|
||||
export type LocalConfiguration = {
|
||||
path: string;
|
||||
@@ -42,7 +43,11 @@ export default class LocalConnectorService implements StorageConnectorAPI {
|
||||
}
|
||||
|
||||
async read(path: string): Promise<Readable> {
|
||||
return createReadStream(this.getFullPath(path));
|
||||
const fullPath = this.getFullPath(path);
|
||||
if (!fs.existsSync(fullPath)) {
|
||||
throw new Error("File doesn't not exists");
|
||||
}
|
||||
return createReadStream(fullPath);
|
||||
}
|
||||
|
||||
async remove(path: string): Promise<boolean> {
|
||||
|
||||
@@ -73,7 +73,7 @@ export default class StorageService extends TdriveService<StorageAPI> implements
|
||||
return await this.getConnector().write(path, stream);
|
||||
} catch (err) {
|
||||
logger.error(err);
|
||||
return null;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,8 +107,7 @@ export default class StorageService extends TdriveService<StorageAPI> implements
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error(err);
|
||||
callback();
|
||||
return;
|
||||
callback(err, null);
|
||||
}
|
||||
callback(null, stream);
|
||||
return;
|
||||
@@ -117,7 +116,7 @@ export default class StorageService extends TdriveService<StorageAPI> implements
|
||||
return new Multistream(factory);
|
||||
} catch (err) {
|
||||
logger.error(err);
|
||||
return null;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ export class FileServiceImpl {
|
||||
entity.application_id = applicationId;
|
||||
entity.upload_data = null;
|
||||
|
||||
this.repository.save(entity, context);
|
||||
await this.repository.save(entity, context);
|
||||
}
|
||||
|
||||
if (file) {
|
||||
@@ -89,7 +89,7 @@ export class FileServiceImpl {
|
||||
size: options.totalSize,
|
||||
chunks: options.totalChunks || 1,
|
||||
};
|
||||
this.repository.save(entity, context);
|
||||
await this.repository.save(entity, context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +109,9 @@ export class FileServiceImpl {
|
||||
}
|
||||
}
|
||||
|
||||
return entity;
|
||||
return await this.getFile({ id: entity.id, company_id: entity.company_id }, context, {
|
||||
waitForThumbnail: options.waitForThumbnail,
|
||||
});
|
||||
}
|
||||
|
||||
async exists(id: string, companyId: string, context?: CompanyExecutionContext): Promise<boolean> {
|
||||
|
||||
@@ -44,13 +44,18 @@ export class FileController {
|
||||
): Promise<void> {
|
||||
const context = getCompanyExecutionContext(request);
|
||||
const params = request.params;
|
||||
const data = await gr.services.files.download(params.id, context);
|
||||
const filename = data.name.replace(/[^a-zA-Z0-9 -_.]/g, "");
|
||||
try {
|
||||
const data = await gr.services.files.download(params.id, context);
|
||||
const filename = data.name.replace(/[^a-zA-Z0-9 -_.]/g, "");
|
||||
|
||||
response.header("Content-disposition", `attachment; filename="${filename}"`);
|
||||
if (data.size) response.header("Content-Length", data.size);
|
||||
response.type(data.mime);
|
||||
response.send(data.file);
|
||||
response.header("Content-disposition", `attachment; filename="${filename}"`);
|
||||
if (data.size) response.header("Content-Length", data.size);
|
||||
response.type(data.mime);
|
||||
response.send(data.file);
|
||||
} catch (e) {
|
||||
console.log("!!!" + e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
async thumbnail(
|
||||
|
||||
@@ -50,6 +50,9 @@ export async function formatUser(
|
||||
const companies = await Promise.all(
|
||||
userCompanies.map(async uc => {
|
||||
const company = await gr.services.companies.getCompany({ id: uc.group_id });
|
||||
if (!company) {
|
||||
throw new Error(`Company with id ${uc.group_id} doesn't exists!`);
|
||||
}
|
||||
return {
|
||||
role: uc.role as CompanyUserRole,
|
||||
status: "active" as CompanyUserStatus, // FIXME: with real status
|
||||
|
||||
Reference in New Issue
Block a user