|
@@ -19,6 +19,12 @@
|
|
*/
|
|
*/
|
|
const BaseService = require("./BaseService");
|
|
const BaseService = require("./BaseService");
|
|
class WSPushService extends BaseService {
|
|
class WSPushService extends BaseService {
|
|
|
|
+ /**
|
|
|
|
+ * Initializes the WSPushService by setting up event listeners for various file system operations.
|
|
|
|
+ *
|
|
|
|
+ * @param {Object} options - The configuration options for the service.
|
|
|
|
+ * @param {Object} options.services - An object containing service dependencies.
|
|
|
|
+ */
|
|
async _init () {
|
|
async _init () {
|
|
this.svc_event = this.services.get('event');
|
|
this.svc_event = this.services.get('event');
|
|
|
|
|
|
@@ -35,12 +41,6 @@ class WSPushService extends BaseService {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- /**
|
|
|
|
- * Initializes the WSPushService by setting up event listeners for various file system operations.
|
|
|
|
- *
|
|
|
|
- * @param {Object} options - The configuration options for the service.
|
|
|
|
- * @param {Object} options.services - An object containing service dependencies.
|
|
|
|
- */
|
|
|
|
async _on_fs_create (key, data) {
|
|
async _on_fs_create (key, data) {
|
|
const { node, context } = data;
|
|
const { node, context } = data;
|
|
|
|
|
|
@@ -58,19 +58,6 @@ class WSPushService extends BaseService {
|
|
const response = await node.getSafeEntry({ thumbnail: true });
|
|
const response = await node.getSafeEntry({ thumbnail: true });
|
|
|
|
|
|
|
|
|
|
- /**
|
|
|
|
- * Emits an upload or download progress event to the relevant socket.
|
|
|
|
- *
|
|
|
|
- * @param {string} key - The event key that triggered this method.
|
|
|
|
- * @param {Object} data - Contains upload_tracker, context, and meta information.
|
|
|
|
- * @param {Object} data.upload_tracker - Tracker for the upload/download progress.
|
|
|
|
- * @param {Object} data.context - Context of the operation.
|
|
|
|
- * @param {Object} data.meta - Additional metadata for the event.
|
|
|
|
- *
|
|
|
|
- * @note This method logs information about the progress event and checks for the presence of a socket ID.
|
|
|
|
- * If the socket ID is missing, it logs an error but does not throw an exception for the Puter V1 release.
|
|
|
|
- * It emits a progress event to the socket if it exists, otherwise, it does nothing if the socket has disconnected.
|
|
|
|
- */
|
|
|
|
const user_id_list = await (async () => {
|
|
const user_id_list = await (async () => {
|
|
// NOTE: Using a set because eventually we will need to dispatch
|
|
// NOTE: Using a set because eventually we will need to dispatch
|
|
// to multiple users, but this is not currently the case.
|
|
// to multiple users, but this is not currently the case.
|
|
@@ -94,12 +81,16 @@ class WSPushService extends BaseService {
|
|
*
|
|
*
|
|
* @param {string} key - The event key.
|
|
* @param {string} key - The event key.
|
|
* @param {Object} data - The event data containing node and context information.
|
|
* @param {Object} data - The event data containing node and context information.
|
|
|
|
+ * @returns {Promise<void>} A promise that resolves when the update has been processed.
|
|
*
|
|
*
|
|
- * @description This method processes 'fs.update.*' events, retrieves necessary metadata,
|
|
|
|
- * and emits an 'outer.gui.item.updated' event to update the GUI for the relevant users.
|
|
|
|
- * It gathers user IDs, merges metadata, and prepares a response object for emission.
|
|
|
|
|
|
+ * @description
|
|
|
|
+ * This method is triggered when a file or directory is updated. It retrieves
|
|
|
|
+ * metadata from the context, fetches the updated node's entry, determines the
|
|
|
|
+ * relevant user IDs, and emits an event to notify the GUI of the update.
|
|
*
|
|
*
|
|
- * @returns {Promise<void>} - Resolves when the event has been processed and emitted.
|
|
|
|
|
|
+ * @note
|
|
|
|
+ * - The method uses a set for user IDs to prepare for future multi-user dispatch.
|
|
|
|
+ * - If no specific user ID is provided in the metadata, it falls back to the node's user ID.
|
|
*/
|
|
*/
|
|
async _on_fs_update (key, data) {
|
|
async _on_fs_update (key, data) {
|
|
const { node, context } = data;
|
|
const { node, context } = data;
|
|
@@ -117,23 +108,6 @@ class WSPushService extends BaseService {
|
|
|
|
|
|
const response = await node.getSafeEntry({ debug: 'hi', thumbnail: true });
|
|
const response = await node.getSafeEntry({ debug: 'hi', thumbnail: true });
|
|
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Handles file system update events.
|
|
|
|
- *
|
|
|
|
- * @param {string} key - The event key.
|
|
|
|
- * @param {Object} data - The event data containing node and context information.
|
|
|
|
- * @returns {Promise<void>} A promise that resolves when the update has been processed.
|
|
|
|
- *
|
|
|
|
- * @description
|
|
|
|
- * This method is triggered when a file or directory is updated. It retrieves
|
|
|
|
- * metadata from the context, fetches the updated node's entry, determines the
|
|
|
|
- * relevant user IDs, and emits an event to notify the GUI of the update.
|
|
|
|
- *
|
|
|
|
- * @note
|
|
|
|
- * - The method uses a set for user IDs to prepare for future multi-user dispatch.
|
|
|
|
- * - If no specific user ID is provided in the metadata, it falls back to the node's user ID.
|
|
|
|
- */
|
|
|
|
const user_id_list = await (async () => {
|
|
const user_id_list = await (async () => {
|
|
// NOTE: Using a set because eventually we will need to dispatch
|
|
// NOTE: Using a set because eventually we will need to dispatch
|
|
// to multiple users, but this is not currently the case.
|
|
// to multiple users, but this is not currently the case.
|
|
@@ -182,18 +156,6 @@ class WSPushService extends BaseService {
|
|
|
|
|
|
const response = await moved.getSafeEntry();
|
|
const response = await moved.getSafeEntry();
|
|
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Handles the file system move event by emitting a GUI update event.
|
|
|
|
- * This method processes the metadata associated with the move operation,
|
|
|
|
- * retrieves safe entry details for the moved item, and notifies relevant users.
|
|
|
|
- *
|
|
|
|
- * @param {string} key - The event key for the move operation.
|
|
|
|
- * @param {Object} data - Contains details of the move operation:
|
|
|
|
- * - moved: The file system entry that was moved.
|
|
|
|
- * - old_path: The original path of the moved item.
|
|
|
|
- * - context: Contextual information for the operation.
|
|
|
|
- */
|
|
|
|
const user_id_list = await (async () => {
|
|
const user_id_list = await (async () => {
|
|
// NOTE: Using a set because eventually we will need to dispatch
|
|
// NOTE: Using a set because eventually we will need to dispatch
|
|
// to multiple users, but this is not currently the case.
|
|
// to multiple users, but this is not currently the case.
|
|
@@ -220,6 +182,7 @@ class WSPushService extends BaseService {
|
|
* @param {Object} data - An object containing the fsentry and context of the pending file system operation.
|
|
* @param {Object} data - An object containing the fsentry and context of the pending file system operation.
|
|
* @param {Object} data.fsentry - The file system entry that is pending.
|
|
* @param {Object} data.fsentry - The file system entry that is pending.
|
|
* @param {Object} data.context - The operation context providing additional metadata.
|
|
* @param {Object} data.context - The operation context providing additional metadata.
|
|
|
|
+ * @fires svc_event#outer.gui.item.pending - Emitted with user ID list and entry details.
|
|
*
|
|
*
|
|
* @returns {Promise<void>} Emits an event to update the GUI about the pending item.
|
|
* @returns {Promise<void>} Emits an event to update the GUI about the pending item.
|
|
*/
|
|
*/
|
|
@@ -239,17 +202,6 @@ class WSPushService extends BaseService {
|
|
Object.assign(metadata, gui_metadata);
|
|
Object.assign(metadata, gui_metadata);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Emits a 'outer.gui.item.pending' event for an FS entry in a pending state.
|
|
|
|
- *
|
|
|
|
- * @param {string} key - The event key triggering this method.
|
|
|
|
- * @param {Object} data - Contains the FS entry data and context.
|
|
|
|
- * @param {Object} data.fsentry - The file system entry object.
|
|
|
|
- * @param {Object} data.context - The context object containing service information.
|
|
|
|
- *
|
|
|
|
- * @fires svc_event#outer.gui.item.pending - Emitted with user ID list and entry details.
|
|
|
|
- */
|
|
|
|
const user_id_list = await (async () => {
|
|
const user_id_list = await (async () => {
|
|
// NOTE: Using a set because eventually we will need to dispatch
|
|
// NOTE: Using a set because eventually we will need to dispatch
|
|
// to multiple users, but this is not currently the case.
|
|
// to multiple users, but this is not currently the case.
|
|
@@ -266,18 +218,16 @@ class WSPushService extends BaseService {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
- * Handles upload progress events.
|
|
|
|
|
|
+ * Emits an upload or download progress event to the relevant socket.
|
|
*
|
|
*
|
|
- * @param {string} key - The event key.
|
|
|
|
- * @param {Object} data - The event data containing upload progress information.
|
|
|
|
- * @returns {Promise<void>} A promise that resolves when the progress has been emitted to the appropriate socket.
|
|
|
|
|
|
+ * @param {string} key - The event key that triggered this method.
|
|
|
|
+ * @param {Object} data - Contains upload_tracker, context, and meta information.
|
|
|
|
+ * @param {Object} data.upload_tracker - Tracker for the upload/download progress.
|
|
|
|
+ * @param {Object} data.context - Context of the operation.
|
|
|
|
+ * @param {Object} data.meta - Additional metadata for the event.
|
|
*
|
|
*
|
|
- * @description
|
|
|
|
- * This method processes upload progress events, logs information,
|
|
|
|
- * prepares metadata, and emits the progress to the client socket associated with the given socket ID.
|
|
|
|
- * If the socket ID is missing or the socket has disconnected, appropriate actions are taken.
|
|
|
|
|
|
+ * It emits a progress event to the socket if it exists, otherwise, it does nothing.
|
|
*/
|
|
*/
|
|
async _on_upload_progress (key, data) {
|
|
async _on_upload_progress (key, data) {
|
|
this.log.info('got upload progress event');
|
|
this.log.info('got upload progress event');
|