MCPcopy
hub / github.com/cryptpad/cryptpad / start

Function start

www/cryptpad-api.js:90–282  ·  view source on GitHub ↗
(config, chan)

Source from the content-addressed store, hash-verified

88
89 let onDocumentReady = [];
90 var start = function (config, chan) {
91 return new Promise(function (resolve, reject) {
92 setTimeout(function () {
93 var docID = config.document.key;
94 var key = config.document.key;
95 const isView = config.mode === 'view';
96 var blob;
97
98 var getBlob = function (cb) {
99 var xhr = new XMLHttpRequest();
100 let url = config.document.url;
101 xhr.open('GET', url, true);
102 xhr.responseType = 'blob';
103 xhr.onload = function () {
104 if (this.status === 200) {
105 var blob = this.response;
106 // myBlob is now the blob that the object URL pointed to.
107 cb(null, blob);
108 } else {
109 cb(this.status);
110 }
111 };
112 xhr.onerror = function (e) {
113 cb(e.message);
114 };
115 xhr.send();
116 };
117
118 let serializedConfig = () => {
119 let _config = {};
120 _config.editorConfig = config.editorConfig;
121 _config.document = {
122 permissions: config.document?.permissions,
123 title: config.document?.title,
124 info: config.document?.info,
125 referenceData: config.document?.referenceData
126 };
127 return _config;
128 };
129
130 var start = function () {
131 //config.document.key = key;
132 const autosave = typeof(config.autosave) === "number" ? config.autosave : 10;
133 chan.send('START', {
134 key: key,
135 application: config.documentType,
136 name: config.document.title,
137 url: config.document.url,
138 documentKey: docID,
139 document: blob,
140 ext: config.document.fileType,
141 autosave: config.events.onSave && autosave,
142 readOnly: isView,
143 editorConfig: config.editorConfig || {},
144 _config: serializedConfig()
145 }, function (obj) {
146 if (obj && obj.error) { reject(obj.error); return console.error(obj.error); }
147 resolve({});

Callers 2

onKeyValidatedFunction · 0.70
onMsgFunction · 0.70

Calls 10

rejectFunction · 0.85
serializedConfigFunction · 0.70
getSessionFunction · 0.70
getBlobFunction · 0.70
makeIframeFunction · 0.70
resolveFunction · 0.50
fFunction · 0.50
cbFunction · 0.50
onMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected