allow to specify user data in some low level VFS interface API

This commit is contained in:
DanyLE 2023-01-31 20:34:07 +01:00 committed by Dany LE
parent d482d2cad4
commit ae91401965
2 changed files with 56 additions and 31 deletions

25
d.ts/antos.d.ts vendored
View File

@ -3634,12 +3634,13 @@ interface HTMLElement {
* element * element
* *
* This will trigger the `dragging` and `drop` event on the enabled * This will trigger the `dragging` and `drop` event on the enabled
* on the element when the mouse is down, then move * element when the mouse is down, move, then up, then move
* *
* The event can be listened using the traditional way, * The event can be listened using the traditional way,
* Example: * Example:
* ``` * ```
* elem.addEventListener('dragging', (e) => { }, false); * elem.addEventListener('dragging', (e) => { }, false);
* elem.addEventListener('drop', (e) => { }, false);
* ``` * ```
* *
* @meberof HTMLElement * @meberof HTMLElement
@ -9718,17 +9719,18 @@ declare namespace OS {
* will return the meta-data of all files inside of the directory. * will return the meta-data of all files inside of the directory.
* Otherwise, file content will be returned * Otherwise, file content will be returned
* *
* @param {string} t data type * @param {any} formal t data type
* - jsonp: the response is an json object * - jsonp: the response is an json object
* - script: the response is a javascript code * - script: the response is a javascript code
* - xml, html: the response is a XML/HTML object * - xml, html: the response is a XML/HTML object
* - text: plain text * - text: plain text
* - binary * - binary
* - other user case may be user specific data
* *
* @returns {Promise<any>} a promise on the file content * @returns {Promise<any>} a promise on the file content
* @memberof BaseFileHandle * @memberof BaseFileHandle
*/ */
read(t?: string): Promise<any>; read(t?: any): Promise<any>;
/** /**
* Write the file cache to the actual file * Write the file cache to the actual file
* *
@ -9757,11 +9759,11 @@ declare namespace OS {
* Delete the file * Delete the file
* *
* This function calls the [[_rm]] function to perform the operation * This function calls the [[_rm]] function to perform the operation
* * @param {any} d user data
* @returns {Promise<RequestResult>} promise on the operation result * @returns {Promise<RequestResult>} promise on the operation result
* @memberof BaseFileHandle * @memberof BaseFileHandle
*/ */
remove(): Promise<RequestResult>; remove(data?: any): Promise<RequestResult>;
/** /**
* Upload a file to the current directory * Upload a file to the current directory
* *
@ -9848,11 +9850,11 @@ declare namespace OS {
* that supports the operation * that supports the operation
* *
* @protected * @protected
* @param {string} t data type, see [[read]] * @param {any} t data type, see [[read]]
* @returns {Promise<RequestResult>} * @returns {Promise<RequestResult>}
* @memberof BaseFileHandle * @memberof BaseFileHandle
*/ */
protected _rd(t: string): Promise<RequestResult>; protected _rd(t: any): Promise<RequestResult>;
/** /**
* Low level protocol-specific write operation * Low level protocol-specific write operation
* *
@ -9861,11 +9863,10 @@ declare namespace OS {
* *
* @protected * @protected
* @param {string} t data type, see [[write]] * @param {string} t data type, see [[write]]
* @param {*} [d]
* @returns {Promise<RequestResult>} * @returns {Promise<RequestResult>}
* @memberof BaseFileHandle * @memberof BaseFileHandle
*/ */
protected _wr(t: string, d?: any): Promise<RequestResult>; protected _wr(t: string): Promise<RequestResult>;
/** /**
* Low level protocol-specific sub-directory creation * Low level protocol-specific sub-directory creation
* *
@ -9884,10 +9885,11 @@ declare namespace OS {
* This function should be overridden by the file handle class * This function should be overridden by the file handle class
* that supports the operation * that supports the operation
* *
* @param {*} [d] any user data
* @returns {Promise<RequestResult>} * @returns {Promise<RequestResult>}
* @memberof BaseFileHandle * @memberof BaseFileHandle
*/ */
protected _rm(): Promise<RequestResult>; protected _rm(d: any): Promise<RequestResult>;
/** /**
* Low level protocol-specific move operation * Low level protocol-specific move operation
* *
@ -10301,11 +10303,10 @@ declare namespace OS {
* *
* @protected * @protected
* @param {string} t data type, see [[write]] * @param {string} t data type, see [[write]]
* @param {string} d file data
* @returns {Promise<RequestResult>} * @returns {Promise<RequestResult>}
* @memberof SharedFileHandle * @memberof SharedFileHandle
*/ */
protected _wr(t: string, d: string): Promise<RequestResult>; protected _wr(t: string): Promise<RequestResult>;
/** /**
* Un-publish the file * Un-publish the file
* *

View File

@ -575,17 +575,18 @@ namespace OS {
* will return the meta-data of all files inside of the directory. * will return the meta-data of all files inside of the directory.
* Otherwise, file content will be returned * Otherwise, file content will be returned
* *
* @param {string} t data type * @param {any} formal t data type
* - jsonp: the response is an json object * - jsonp: the response is an json object
* - script: the response is a javascript code * - script: the response is a javascript code
* - xml, html: the response is a XML/HTML object * - xml, html: the response is a XML/HTML object
* - text: plain text * - text: plain text
* - binary * - binary
* - other user case may be user specific data
* *
* @returns {Promise<any>} a promise on the file content * @returns {Promise<any>} a promise on the file content
* @memberof BaseFileHandle * @memberof BaseFileHandle
*/ */
read(t?: string): Promise<any> { read(t?: any): Promise<any> {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
try { try {
const r = await this.onready(); const r = await this.onready();
@ -648,15 +649,15 @@ namespace OS {
* Delete the file * Delete the file
* *
* This function calls the [[_rm]] function to perform the operation * This function calls the [[_rm]] function to perform the operation
* * @param {any} d user data
* @returns {Promise<RequestResult>} promise on the operation result * @returns {Promise<RequestResult>} promise on the operation result
* @memberof BaseFileHandle * @memberof BaseFileHandle
*/ */
remove(): Promise<RequestResult> { remove(data?: any): Promise<RequestResult> {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
try { try {
const r = await this.onready(); const r = await this.onready();
const d = await this._rm(); const d = await this._rm(data);
announcer.ostrigger("VFS", "remove",this); announcer.ostrigger("VFS", "remove",this);
return resolve(d); return resolve(d);
} catch (e_1) { } catch (e_1) {
@ -830,11 +831,11 @@ namespace OS {
* that supports the operation * that supports the operation
* *
* @protected * @protected
* @param {string} t data type, see [[read]] * @param {any} t data type, see [[read]]
* @returns {Promise<RequestResult>} * @returns {Promise<RequestResult>}
* @memberof BaseFileHandle * @memberof BaseFileHandle
*/ */
protected _rd(t: string): Promise<RequestResult> { protected _rd(t: any): Promise<RequestResult> {
return this.unsupported("read"); return this.unsupported("read");
} }
@ -846,11 +847,10 @@ namespace OS {
* *
* @protected * @protected
* @param {string} t data type, see [[write]] * @param {string} t data type, see [[write]]
* @param {*} [d]
* @returns {Promise<RequestResult>} * @returns {Promise<RequestResult>}
* @memberof BaseFileHandle * @memberof BaseFileHandle
*/ */
protected _wr(t: string, d?: any): Promise<RequestResult> { protected _wr(t: string): Promise<RequestResult> {
return this.unsupported("write"); return this.unsupported("write");
} }
@ -874,10 +874,11 @@ namespace OS {
* This function should be overridden by the file handle class * This function should be overridden by the file handle class
* that supports the operation * that supports the operation
* *
* @param {*} [d] any user data
* @returns {Promise<RequestResult>} * @returns {Promise<RequestResult>}
* @memberof BaseFileHandle * @memberof BaseFileHandle
*/ */
protected _rm(): Promise<RequestResult> { protected _rm(d: any): Promise<RequestResult> {
return this.unsupported("remove"); return this.unsupported("remove");
} }
@ -1875,22 +1876,45 @@ namespace OS {
* *
* @protected * @protected
* @param {string} t data type, see [[write]] * @param {string} t data type, see [[write]]
* @param {string} d file data
* @returns {Promise<RequestResult>} * @returns {Promise<RequestResult>}
* @memberof SharedFileHandle * @memberof SharedFileHandle
*/ */
protected _wr(t: string, d: string): Promise<RequestResult> { protected _wr(t: string): Promise<RequestResult> {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
try { try {
const r = await API.handle.write(this.path, d);
if (r.error) { if (t === "base64") {
const d = await API.handle.write(
this.path,
this.cache
);
if (d.error) {
return reject( return reject(
API.throwe( API.throwe(
__("{0}: {1}", r.error, this.path) __("{0}: {1}", d.error, this.path)
) )
); );
} }
return resolve(r); return resolve(d);
} else {
const r = await this.b64(t);
const result = await API.handle.write(
this.path,
r as string
);
if (result.error) {
return reject(
API.throwe(
__(
"{0}: {1}",
result.error,
this.path
)
)
);
}
return resolve(result);
}
} catch (e) { } catch (e) {
return reject(__e(e)); return reject(__e(e));
} }