✨Added support of the session editing key for the OnlyOffice connector
This commit is contained in:
committed by
Eric Doughty-Papassideris
parent
b6be90f825
commit
c66123f450
@@ -61,6 +61,8 @@ import archiver from "archiver";
|
||||
import internal from "stream";
|
||||
import config from "config";
|
||||
import { randomUUID } from "crypto";
|
||||
import { MultipartFile } from "@fastify/multipart";
|
||||
import { UploadOptions } from "src/services/files/types";
|
||||
|
||||
export class DocumentsService {
|
||||
version: "1";
|
||||
@@ -1030,13 +1032,15 @@ export class DocumentsService {
|
||||
* End editing session either by providing a URL to a new file to create a version,
|
||||
* or not, to just cancel the session.
|
||||
* @param editing_session_key Editing key of the DriveFile
|
||||
* @param newFileUrl Optional URL to a new version of the file to store
|
||||
* @param file Multipart files from the incoming http request
|
||||
* @param options Optional upload information from the request
|
||||
* @param context
|
||||
*/
|
||||
endEditing = async (
|
||||
editing_session_key: string,
|
||||
newFileUrl: string | null,
|
||||
context: DriveExecutionContext,
|
||||
file: MultipartFile,
|
||||
options: UploadOptions,
|
||||
context: CompanyExecutionContext,
|
||||
) => {
|
||||
if (!context) {
|
||||
this.logger.error("invalid execution context");
|
||||
@@ -1062,19 +1066,21 @@ export class DocumentsService {
|
||||
);
|
||||
}
|
||||
|
||||
if (newFileUrl) {
|
||||
// const response = await axios.request({
|
||||
// url: domain + req.url,
|
||||
// method: req.method as any,
|
||||
// headers: _.omit(req.headers, "host", "content-length") as {
|
||||
// [key: string]: string;
|
||||
// },
|
||||
// data: req.body as any,
|
||||
// responseType: "stream",
|
||||
// maxRedirects: 0,
|
||||
// validateStatus: null,
|
||||
// });
|
||||
//TODO: save file into new version
|
||||
if (file) {
|
||||
const fileEntity = await globalResolver.services.files.save(null, file, options, context);
|
||||
|
||||
await globalResolver.services.documents.documents.createVersion(
|
||||
driveFile.id,
|
||||
{
|
||||
drive_item_id: driveFile.id,
|
||||
provider: "internal",
|
||||
file_metadata: {
|
||||
external_id: fileEntity.id,
|
||||
source: "internal",
|
||||
},
|
||||
},
|
||||
context,
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -1092,7 +1098,6 @@ export class DocumentsService {
|
||||
result.currentValue,
|
||||
)}`,
|
||||
);
|
||||
return { ok: true };
|
||||
} catch (error) {
|
||||
logger.error({ error: `${error}` }, "Failed to cancel editing Drive item");
|
||||
CrudException.throwMe(error, new CrudException("Failed to cancel editing Drive item", 500));
|
||||
|
||||
@@ -392,6 +392,7 @@ export class DocumentsController {
|
||||
return await globalResolver.services.documents.documents.endEditing(
|
||||
editing_session_key,
|
||||
null,
|
||||
null,
|
||||
context,
|
||||
);
|
||||
} catch (error) {
|
||||
@@ -406,10 +407,44 @@ export class DocumentsController {
|
||||
endEditing = async (
|
||||
request: FastifyRequest<{
|
||||
Params: ItemRequestByEditingSessionKeyParams;
|
||||
Body: { editorApplicationId: string };
|
||||
Querystring: Record<string, string>;
|
||||
Body: {
|
||||
item: Partial<DriveFile>;
|
||||
version: Partial<FileVersion>;
|
||||
};
|
||||
}>,
|
||||
) => {
|
||||
console.log(request); // make linter happy
|
||||
const { editing_session_key } = request.params;
|
||||
if (!editing_session_key) throw new CrudException("Editing session key must be set", 400);
|
||||
|
||||
const context = getDriveExecutionContext(request);
|
||||
|
||||
if (request.isMultipart()) {
|
||||
const file = await request.file();
|
||||
const q: Record<string, string> = request.query;
|
||||
const options: UploadOptions = {
|
||||
totalChunks: parseInt(q.resumableTotalChunks || q.total_chunks) || 1,
|
||||
totalSize: parseInt(q.resumableTotalSize || q.total_size) || 0,
|
||||
chunkNumber: parseInt(q.resumableChunkNumber || q.chunk_number) || 1,
|
||||
filename: q.resumableFilename || q.filename || file?.filename || undefined,
|
||||
type: q.resumableType || q.type || file?.mimetype || undefined,
|
||||
waitForThumbnail: !!q.thumbnail_sync,
|
||||
ignoreThumbnails: false,
|
||||
};
|
||||
return await globalResolver.services.documents.documents.endEditing(
|
||||
editing_session_key,
|
||||
file,
|
||||
options,
|
||||
context,
|
||||
);
|
||||
} else {
|
||||
return await globalResolver.services.documents.documents.endEditing(
|
||||
editing_session_key,
|
||||
null,
|
||||
null,
|
||||
context,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
downloadGetToken = async (
|
||||
|
||||
@@ -105,7 +105,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, _options, next)
|
||||
method: "DELETE",
|
||||
url: `${serviceUrl}/editing_session/:editing_session_key`,
|
||||
preValidation: [fastify.authenticateOptional],
|
||||
handler: documentsController.endEditing.bind(documentsController),
|
||||
handler: documentsController.cancelEditing.bind(documentsController),
|
||||
});
|
||||
|
||||
fastify.route({
|
||||
|
||||
Reference in New Issue
Block a user