🐛 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);
|
return new CrudException(details, 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static unauthorized(details: string): CrudException {
|
||||||
|
return new CrudException(details, 401);
|
||||||
|
}
|
||||||
|
|
||||||
static notFound(details: string): CrudException {
|
static notFound(details: string): CrudException {
|
||||||
return new CrudException(details, 404);
|
return new CrudException(details, 404);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import config from "../../../../config";
|
|||||||
import { JwtType } from "../../types";
|
import { JwtType } from "../../types";
|
||||||
import { executionStorage } from "../../../framework/execution-storage";
|
import { executionStorage } from "../../../framework/execution-storage";
|
||||||
import gr from "../../../../../services/global-resolver";
|
import gr from "../../../../../services/global-resolver";
|
||||||
|
import { CrudException } from "../../../framework/api/crud-service";
|
||||||
|
|
||||||
const jwtPlugin: FastifyPluginCallback = async (fastify, _opts, next) => {
|
const jwtPlugin: FastifyPluginCallback = async (fastify, _opts, next) => {
|
||||||
fastify.register(cookie);
|
fastify.register(cookie);
|
||||||
@@ -50,7 +51,7 @@ const jwtPlugin: FastifyPluginCallback = async (fastify, _opts, next) => {
|
|||||||
try {
|
try {
|
||||||
await authenticate(request);
|
await authenticate(request);
|
||||||
} catch (err) {
|
} 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,
|
context: CompanyExecutionContext,
|
||||||
prefix?: string,
|
prefix?: string,
|
||||||
): Promise<void> => {
|
): 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) {
|
if (!item) {
|
||||||
throw Error("item not found");
|
throw Error(`Item '${JSON.stringify(itemPK)}' not found`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!item.is_directory) {
|
if (!item.is_directory) {
|
||||||
|
|||||||
@@ -427,6 +427,8 @@ export class DocumentsController {
|
|||||||
});
|
});
|
||||||
|
|
||||||
archive.pipe(reply.raw);
|
archive.pipe(reply.raw);
|
||||||
|
|
||||||
|
return reply;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error({ error: `${error}` }, "failed to send zip file");
|
logger.error({ error: `${error}` }, "failed to send zip file");
|
||||||
throw new CrudException("Failed to create zip file", 500);
|
throw new CrudException("Failed to create zip file", 500);
|
||||||
|
|||||||
@@ -400,7 +400,7 @@ export default class UserApi {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
async getFolder(id: string | "root" | "trash" | "shared_with_me") {
|
async zipDocument(id: string | "root" | "trash" | "shared_with_me") {
|
||||||
return await this.platform.app.inject({
|
return await this.platform.app.inject({
|
||||||
method: "GET",
|
method: "GET",
|
||||||
url: `${UserApi.DOC_URL}/companies/${this.platform.workspace.company_id}/item/download/zip?items=${id}`,
|
url: `${UserApi.DOC_URL}/companies/${this.platform.workspace.company_id}/item/download/zip?items=${id}`,
|
||||||
@@ -410,7 +410,6 @@ export default class UserApi {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
async getDocumentOKCheck(id: string | "root" | "trash" | "shared_with_me") {
|
async getDocumentOKCheck(id: string | "root" | "trash" | "shared_with_me") {
|
||||||
const response = await this.getDocument(id);
|
const response = await this.getDocument(id);
|
||||||
expect(response.statusCode).toBe(200);
|
expect(response.statusCode).toBe(200);
|
||||||
@@ -418,13 +417,6 @@ export default class UserApi {
|
|||||||
expect(doc.item?.id).toBe(id);
|
expect(doc.item?.id).toBe(id);
|
||||||
};
|
};
|
||||||
|
|
||||||
async getFolderOKCheck(id: string | "root" | "trash" | "shared_with_me") {
|
|
||||||
const response = await this.getFolder(id);
|
|
||||||
expect(response.statusCode).toBe(200);
|
|
||||||
const doc = deserialize<DriveItemDetailsMockClass>(DriveItemDetailsMockClass, response.body);
|
|
||||||
expect(doc.item?.id).toBe(id);
|
|
||||||
};
|
|
||||||
|
|
||||||
async sharedWithMeDocuments(
|
async sharedWithMeDocuments(
|
||||||
payload: Record<string, any>
|
payload: Record<string, any>
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -106,6 +106,22 @@ describe("the Drive feature", () => {
|
|||||||
expect(updateItemResult.name).toEqual("somethingelse");
|
expect(updateItemResult.name).toEqual("somethingelse");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Download folder as a zip should work fine", async () => {
|
||||||
|
//given
|
||||||
|
const folder = await currentUser.createDirectory("user_" + currentUser.user.id)
|
||||||
|
await currentUser.uploadRandomFileAndCreateDocument(folder.id);
|
||||||
|
|
||||||
|
//when
|
||||||
|
const zipResponse = await currentUser.zipDocument(folder.id);
|
||||||
|
|
||||||
|
//then
|
||||||
|
expect(zipResponse).toBeTruthy();
|
||||||
|
expect(zipResponse.statusCode).toBe(200);
|
||||||
|
|
||||||
|
//and data is in place
|
||||||
|
expect(zipResponse.body.length).toBeGreaterThanOrEqual(100);
|
||||||
|
});
|
||||||
|
|
||||||
it("did move an item to trash", async () => {
|
it("did move an item to trash", async () => {
|
||||||
const createItemResult = await currentUser.createDefaultDocument();
|
const createItemResult = await currentUser.createDefaultDocument();
|
||||||
|
|
||||||
|
|||||||
@@ -286,7 +286,7 @@ describe("the public links feature", () => {
|
|||||||
anotherUser.jwt = token.value;
|
anotherUser.jwt = token.value;
|
||||||
await anotherUser.getDocumentOKCheck(doc.id);
|
await anotherUser.getDocumentOKCheck(doc.id);
|
||||||
|
|
||||||
expect((await anotherUser.getFolder(doc.id)).statusCode).toBe(200);
|
expect((await anotherUser.zipDocument(doc.id)).statusCode).toBe(200);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user