backend cli: add editing_session list viewer command (and minor instanceId fixes) (#525)

This commit is contained in:
Eric Doughty-Papassideris
2024-09-15 00:03:49 +02:00
parent 53b34a0962
commit 1e16e179b0
3 changed files with 65 additions and 3 deletions
@@ -135,7 +135,8 @@ const OnlyOfficeSafeDocKeyBase64 = {
},
};
function checkFieldValue(field: string, value: string) {
function checkFieldValue(field: string, value: string, required: boolean = true) {
if (!required && !value) return;
if (!/^[0-9a-zA-Z_-]+$/m.test(value))
throw new Error(
`Invalid ${field} value (${JSON.stringify(
@@ -143,7 +144,12 @@ function checkFieldValue(field: string, value: string) {
)}). Must be short and only alpha numeric or '_' and '-'`,
);
}
/** Reference implementation for generating then parsing the {@link DriveFile.editing_session_key} field */
/**
* Reference implementation for generating then parsing the {@link DriveFile.editing_session_key} field.
*
* Fields should be explicit, `instanceId` is for the case when we have multiple
* clients
*/
export const EditingSessionKeyFormat = {
// OnlyOffice key limits: 128 chars, [0-9a-zA-Z.=_-]
// See https://api.onlyoffice.com/editors/config/document#key
@@ -161,7 +167,7 @@ export const EditingSessionKeyFormat = {
overrideTimeStamp?: Date,
) {
checkFieldValue("applicationId", applicationId);
checkFieldValue("instanceId", instanceId);
checkFieldValue("instanceId", instanceId, false);
const isoUTCDateNoSpecialCharsNoMS = (overrideTimeStamp ?? new Date())
.toISOString()
.replace(/\..+$/, "")
@@ -959,6 +959,8 @@ export class DocumentsService {
* with only that key provided.
* @param id DriveFile ID of the document to begin editing
* @param editorApplicationId Editor/Application/Plugin specific identifier
* @param appInstanceId For that `editorApplicationId` a unique identifier
* when multiple instances are running. Unused today.
* @param context
* @returns An object in the format `{}` with the unique identifier for the
* editing session