🐛 Fixed bug with downloading zip folder (#541)
* 🐛Fixed bug with downloading zip folder * ♻️Removed unused method
This commit is contained in:
@@ -135,6 +135,10 @@ export class CrudException extends Error {
|
||||
return new CrudException(details, 400);
|
||||
}
|
||||
|
||||
static unauthorized(details: string): CrudException {
|
||||
return new CrudException(details, 401);
|
||||
}
|
||||
|
||||
static notFound(details: string): CrudException {
|
||||
return new CrudException(details, 404);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import config from "../../../../config";
|
||||
import { JwtType } from "../../types";
|
||||
import { executionStorage } from "../../../framework/execution-storage";
|
||||
import gr from "../../../../../services/global-resolver";
|
||||
import { CrudException } from "../../../framework/api/crud-service";
|
||||
|
||||
const jwtPlugin: FastifyPluginCallback = async (fastify, _opts, next) => {
|
||||
fastify.register(cookie);
|
||||
@@ -50,7 +51,7 @@ const jwtPlugin: FastifyPluginCallback = async (fastify, _opts, next) => {
|
||||
try {
|
||||
await authenticate(request);
|
||||
} catch (err) {
|
||||
throw fastify.httpErrors.unauthorized(`Bad credentials ${JSON.stringify(err)}`);
|
||||
throw CrudException.unauthorized(`Bad credentials: ${err.message}`);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -311,10 +311,11 @@ export const addDriveItemToArchive = async (
|
||||
context: CompanyExecutionContext,
|
||||
prefix?: string,
|
||||
): Promise<void> => {
|
||||
const item = entity || (await repository.findOne({ id, company_id: context.company.id }));
|
||||
const itemPK = { id, company_id: context.company.id };
|
||||
const item = entity || (await repository.findOne(itemPK));
|
||||
|
||||
if (!item) {
|
||||
throw Error("item not found");
|
||||
throw Error(`Item '${JSON.stringify(itemPK)}' not found`);
|
||||
}
|
||||
|
||||
if (!item.is_directory) {
|
||||
|
||||
@@ -427,6 +427,8 @@ export class DocumentsController {
|
||||
});
|
||||
|
||||
archive.pipe(reply.raw);
|
||||
|
||||
return reply;
|
||||
} catch (error) {
|
||||
logger.error({ error: `${error}` }, "failed to send zip file");
|
||||
throw new CrudException("Failed to create zip file", 500);
|
||||
|
||||
Reference in New Issue
Block a user