Add support for readOnly mode in API

This commit is contained in:
yflory 2025-06-05 12:57:18 +02:00
parent a3552a9250
commit 03a84fe127
5 changed files with 22 additions and 14 deletions

View File

@ -2136,6 +2136,19 @@ define([
}
};
const copy = (a, b) => {
Object.keys(b).forEach(k => {
if (k === "user") { return; } // Don't change user values
if (a[k]) {
if (typeof(a[k]) === "object" && typeof(b[k]) === "object") {
copy(a[k], b[k]);
}
return;
}
a[k] = b[k];
});
};
const createOOConfig = function(blob, file, lock, fromContent, lang, force) {
const url = URL.createObjectURL(blob);
let username = Util.find(privateData, ['integrationConfig', 'user', 'name'])
@ -2185,18 +2198,6 @@ define([
}
};
let copy = (a, b) => {
Object.keys(b).forEach(k => {
if (k === "user") { return; } // Don't change user values
if (a[k]) {
if (typeof(a[k]) === "object" && typeof(b[k]) === "object") {
copy(a[k], b[k]);
}
return;
}
a[k] = b[k];
});
};
if (integrationConfig) {
let ec = integrationConfig.editorConfig;
let c = ooconfig.editorConfig.customization;

View File

@ -776,8 +776,13 @@ define([
};
var setFileImporter = function (options, fi, async) {
if (readOnly) { return; }
const priv = cpNfInner.metadataMgr.getPrivateData();
const isReadOnlyIntegration = priv.isNewFile &&
Boolean(priv.integrationConfig) &&
priv.initialState;
if (readOnly && !isReadOnlyIntegration) { return; }
fileImporter = function (c, f) {
console.error(state, STATE.READY, unsyncMode);
if (state !== STATE.READY || unsyncMode) {
return void UI.warn(Messages.disconnected);
}

View File

@ -799,7 +799,7 @@ define([
origin: window.location.origin,
pathname: window.location.pathname,
fileHost: ApiConfig.fileHost,
readOnly: readOnly,
readOnly: cfg?.integrationConfig?.readOnly || readOnly,
isTemplate: isTemplate,
newTemplate: Array.isArray(Cryptpad.initialPath)
&& Cryptpad.initialPath[0] === "template",

View File

@ -135,6 +135,7 @@
document: blob,
ext: config.document.fileType,
autosave: config.events.onSave && (config.autosave || 10),
readOnly: config.mode === 'view',
editorConfig: config.editorConfig || {},
_config: serializedConfig()
}, function (obj) {

View File

@ -240,6 +240,7 @@ define([
href: href,
initialState: blob,
config: {
readOnly: data.readOnly,
fileName: data.name,
fileType: data.ext,
autosave: data.autosave,