mirror of
https://github.com/HeyPuter/puter.git
synced 2026-08-12 09:11:54 +00:00
dev(fs): fetch subdomains using join in readdir (#2647)
* dev(fs): fetch subdomains using join in readdir * fix(fs): handle readdir of root directory
This commit is contained in:
@@ -66,11 +66,13 @@ class HLReadDir extends HLFilesystemOperation {
|
||||
|
||||
let children;
|
||||
|
||||
this.log.debug('READDIR',
|
||||
{
|
||||
userdir: await subject.isUserDirectory(),
|
||||
namediff: await subject.get('name') !== user.username,
|
||||
});
|
||||
this.log.debug(
|
||||
'READDIR',
|
||||
{
|
||||
userdir: await subject.isUserDirectory(),
|
||||
namediff: await subject.get('name') !== user.username,
|
||||
},
|
||||
);
|
||||
if ( subject.isRoot ) {
|
||||
const ll_listusers = new LLListUsers();
|
||||
children = await ll_listusers.run(this.values);
|
||||
@@ -123,7 +125,8 @@ class HLReadDir extends HLFilesystemOperation {
|
||||
}
|
||||
|
||||
if ( ! no_subdomains ) {
|
||||
await this.#batchFetchSubdomains(children, user);
|
||||
// await this.#batchFetchSubdomains(children, user);
|
||||
await this.#applySubdomains(children);
|
||||
}
|
||||
|
||||
return Promise.all(children.map(async child => {
|
||||
@@ -142,6 +145,17 @@ class HLReadDir extends HLFilesystemOperation {
|
||||
}));
|
||||
}
|
||||
|
||||
async #applySubdomains (children) {
|
||||
for ( const child of children ) {
|
||||
if ( ! child.subdomains ) return;
|
||||
if ( child.subdomains.length > 0 ) child.has_website = true;
|
||||
for ( const subdomain of child.subdomains ) {
|
||||
subdomain.address =
|
||||
`${config.protocol}://${subdomain.subdomain}.puter.site`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async #batchFetchSubdomains (children, user) {
|
||||
const childIds = [];
|
||||
const childById = new Map();
|
||||
@@ -160,10 +174,12 @@ class HLReadDir extends HLFilesystemOperation {
|
||||
|
||||
const placeholders = childIds.map(() => '?').join(',');
|
||||
const db = this.context.get('services').get('database').get(DB_READ, 'filesystem');
|
||||
const rows = await db.read(`SELECT root_dir_id, subdomain, uuid
|
||||
const rows = await db.read(
|
||||
`SELECT root_dir_id, subdomain, uuid
|
||||
FROM subdomains
|
||||
WHERE root_dir_id IN (${placeholders}) AND user_id = ?`,
|
||||
[...childIds, user.id]);
|
||||
[...childIds, user.id],
|
||||
);
|
||||
|
||||
for ( const row of rows ) {
|
||||
const child = childById.get(row.root_dir_id);
|
||||
|
||||
@@ -169,6 +169,10 @@ class NodeRawEntrySelector extends NodeSelector {
|
||||
node.uid = this.entry.uid ?? this.entry.uuid;
|
||||
node.name = this.entry.name;
|
||||
if ( this.entry.path ) node.path = this.entry.path;
|
||||
|
||||
if ( this.entry.subdomains ) {
|
||||
node.subdomains = this.entry.subdomains;
|
||||
}
|
||||
}
|
||||
|
||||
describe () {
|
||||
|
||||
Reference in New Issue
Block a user