Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 56 additions & 3 deletions extensions/puterfs/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const {

const {
FSNodeContext,
capabilities,
} = extension.import('fs');

const {
Expand All @@ -99,6 +100,25 @@ const {
} = extension.import('fs').util;

class PuterFSProvider {
// TODO: should this be a static member instead?
get_capabilities () {
return new Set([
capabilities.THUMBNAIL,
capabilities.UPDATE_THUMBNAIL,
capabilities.UUID,
capabilities.OPERATION_TRACE,
capabilities.READDIR_UUID_MODE,

capabilities.COPY_TREE,

capabilities.READ,
capabilities.WRITE,
capabilities.CASE_SENSITIVE,
capabilities.SYMLINK,
capabilities.TRASH,
]);
}

/**
* Check if a given node exists.
*
Expand Down Expand Up @@ -226,6 +246,41 @@ class PuterFSProvider {
return node;
}

async update_thumbnail ({ context, node, thumbnail }) {
const {
actor: inputActor,
} = context.values;
const actor = inputActor ?? Context.get('actor');

context = context ?? Context.get();
const services = context.get('services');

// TODO: this ACL check should not be here, but there's no LL method yet
// and it's possible we will never implement the thumbnail
// capability for any other filesystem type

const svc_acl = services.get('acl');
if ( ! await svc_acl.check(actor, node, 'write') ) {
throw await svc_acl.get_safe_acl_error(actor, node, 'write');
}

const uid = await node.get('uid');

const entryOp = await svc_fsEntry.update(uid, {
thumbnail,
});

(async () => {
await entryOp.awaitDone();
svc_event.emit('fs.write.file', {
node,
context,
});
})();

return node;
}

async read ({ context, node, version_id, range }) {
const svc_mountpoint = context.get('services').get('mountpoint');
const storage = svc_mountpoint.get_storage(this.constructor.name);
Expand Down Expand Up @@ -863,12 +918,10 @@ class PuterFSProvider {
}
}

const { TmpProxyFSProvider } = extension.import('fs');

extension.on('create.filesystem-types', event => {
event.createFilesystemType('puterfs', {
mount ({ path }) {
return new TmpProxyFSProvider(path, new PuterFSProvider(path));
return new PuterFSProvider(path);
},
});
});
9 changes: 4 additions & 5 deletions src/backend/src/filesystem/FilesystemService.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const { UserActorType } = require('../services/auth/Actor');
const { get_user } = require('../helpers');
const BaseService = require('../services/BaseService');
const { MANAGE_PERM_PREFIX } = require('../services/auth/permissionConts.mjs');
const { PuterFSProvider } = require('../modules/puterfs/lib/PuterFSProvider.js');
const { quot } = require('@heyputer/putility/src/libs/string.js');

class FilesystemService extends BaseService {
Expand Down Expand Up @@ -95,7 +94,7 @@ class FilesystemService extends BaseService {
|| permission.startsWith(`${MANAGE_PERM_PREFIX}:${MANAGE_PERM_PREFIX}:fs:`); // owner has implicit rule to give others manage access;
},
checker: async ({ actor, permission }) => {
if ( !(actor.type instanceof UserActorType) ) {
if ( ! (actor.type instanceof UserActorType) ) {
return undefined;
}

Expand All @@ -109,7 +108,7 @@ class FilesystemService extends BaseService {
const owner_id = await node.get('user_id');

// These conditions should never happen
if ( ! owner_id || ! actor.type.user.id ) {
if ( !owner_id || !actor.type.user.id ) {
throw new Error('something unexpected happened');
}

Expand Down Expand Up @@ -330,8 +329,8 @@ class FilesystemService extends BaseService {
}

if ( ! (selector instanceof NodeSelector) ) {
throw new Error('FileSystemService could not resolve the specified node value ' +
quot('' + selector) + ` (type: ${typeof selector}) ` +
throw new Error(`FileSystemService could not resolve the specified node value ${
quot(`${ selector}`) } (type: ${typeof selector}) ` +
'to a filesystem node selector');
}

Expand Down
2 changes: 0 additions & 2 deletions src/backend/src/modules/puterfs/PuterFSModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const FSNodeContext = require('../../filesystem/FSNodeContext');
const capabilities = require('../../filesystem/definitions/capabilities');
const selectors = require('../../filesystem/node/selectors');
const { RuntimeModule } = require('../../extension/RuntimeModule');
const { TmpProxyFSProvider } = require('./TmpProxyFSProvider');
const { MODE_READ, MODE_WRITE } = require('../../services/fs/FSLockService');
const { UploadProgressTracker } = require('../../filesystem/storage/UploadProgressTracker');

Expand All @@ -39,7 +38,6 @@ class PuterFSModule extends AdvancedBase {
capabilities,
selectors,
FSNodeContext,
TmpProxyFSProvider,
lock: {
MODE_READ,
MODE_WRITE,
Expand Down
41 changes: 0 additions & 41 deletions src/backend/src/modules/puterfs/PuterFSService.js

This file was deleted.

40 changes: 0 additions & 40 deletions src/backend/src/modules/puterfs/TmpProxyFSProvider.js

This file was deleted.

Loading