Przeglądaj źródła

prereq: make it possible to access storage without context init

KernelDeimos 11 miesięcy temu
rodzic
commit
9ad04cd33f

+ 3 - 0
packages/backend/src/CoreModule.js

@@ -292,6 +292,9 @@ const install = async ({ services, app, useapi }) => {
     
     const { PermissionAPIService } = require('./services/PermissionAPIService');
     services.registerService('__permission-api', PermissionAPIService);
+
+    const { MountpointService } = require('./services/MountpointService');
+    services.registerService('mountpoint', MountpointService);
 }
 
 const install_legacy = async ({ services }) => {

+ 2 - 1
packages/backend/src/filesystem/ll_operations/ll_write.js

@@ -49,7 +49,8 @@ class LLWriteBase extends LLFilesystemOperation {
         const errors = svc.get('error-service').create(log);
         const svc_event = svc.get('event');
 
-        const storage = Context.get('storage');
+        const svc_mountpoint = svc.get('mountpoint');
+        const storage = svc_mountpoint.get_storage();
 
         bucket        ??= config.s3_bucket;
         bucket_region ??= config.s3_region;

+ 3 - 1
packages/backend/src/helpers.js

@@ -1057,7 +1057,9 @@ async function deleteUser(user_id){
         for(let i=0; i<files.length; i++){
             // init S3 SDK
             const svc_fs = Context.get('services').get('filesystem');
-            const storage = Context.get('storage');
+            const svc_mountpoint =
+                Context.get('services').get('mountpoint');
+            const storage = svc_mountpoint.get_storage();
             const op_delete = storage.create_delete();
             await op_delete.run({
                 node: await svc_fs.node(new NodeUIDSelector(files[i].uuid))

+ 3 - 0
packages/backend/src/services/LocalDiskStorageService.js

@@ -31,6 +31,9 @@ class LocalDiskStorageService extends BaseService {
         const svc_contextInit = this.services.get('context-init');
         const storage = new LocalDiskStorageStrategy({ services: this.services });
         svc_contextInit.register_value('storage', storage);
+        
+        const svc_mountpoint = this.services.get('mountpoint');
+        svc_mountpoint.set_storage(storage);
     }
 
     async _init () {

+ 32 - 0
packages/backend/src/services/MountpointService.js

@@ -0,0 +1,32 @@
+// const Mountpoint = o => ({ ...o });
+
+const BaseService = require("./BaseService");
+
+/**
+ * This will eventually be a service which manages the storage
+ * backends for mountpoints.
+ * 
+ * For the moment, this is a way to access the storage backend
+ * in situations where ContextInitService isn't able to
+ * initialize a context.
+ */
+class MountpointService extends BaseService {
+    async _init () {
+        // this.mountpoints_ = {};
+        
+        // Temporary solution - we'll develop this incrementally
+        this.storage_ = null;
+    }
+    
+    // Temporary solution - we'll develop this incrementally
+    set_storage (storage) {
+        this.storage_ = storage;
+    }
+    get_storage () {
+        return this.storage_;
+    }
+}
+
+module.exports = {
+    MountpointService,
+};