Files
Daniel Salazar 99d96edd9c feat: s3 fs in oss (#2761)
* feat: s3 fs in oss

* feat: new endpoints in OSS

* fix: name of fs extension

* perf: signed uploads

* fix: await socket events to align fs events

* fix: default bucket names

* fix: backend tests

* fix: deps

* fix: order
2026-04-02 11:20:59 -07:00

78 lines
2.6 KiB
JavaScript

/*
* Copyright (C) 2024-present Puter Technologies Inc.
*
* This file is part of Puter.
*
* Puter is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import FSEntryController from './fsentries/FSEntryController.js';
import PuterFSProvider from './PuterFSProvider.js';
import ProxyStorageController from './storage/ProxyStorageController.js';
import S3StorageController from './storage/S3StorageController.js';
const svc_event = extension.import('service:event');
const fsEntryController = new FSEntryController();
const storageController = new ProxyStorageController();
extension.on('init', async () => {
fsEntryController.init();
// Keep track of possible storage strategies for puterfs here
let defaultStorage = 'S3';
const storageStrategies = {
'S3': new S3StorageController(),
};
// Emit the "create storage strategies" event
const event = {
createStorageStrategy (name, implementation) {
storageStrategies[name] = implementation;
if ( implementation === undefined ) {
throw new Error('createStorageStrategy was called wrong');
}
if ( implementation.forceDefault ) {
defaultStorage = name;
}
},
};
// Awaiting the event ensures all the storage strategies are registered
await svc_event.emit('puterfs.storage.create', event);
let configuredStorage = defaultStorage;
if ( config.storage ) configuredStorage = config.storage;
// Not we can select the configured strategy
const storageToUse = storageStrategies[configuredStorage];
storageController.setDelegate(storageToUse);
// The StorageController may need to await some asynchronous operations
// before it's ready to be used.
await storageController.init();
});
extension.on('create.filesystem-types', event => {
const fsProvider = new PuterFSProvider({
fsEntryController,
storageController,
});
event.createFilesystemType('puterfs', {
mount ({ path }) {
return fsProvider;
},
});
});