mirror of
https://github.com/HeyPuter/puter.git
synced 2026-05-03 16:10:31 +00:00
feat: search endpoint
Docker Image CI / build-and-push-image (push) Waiting to run
Maintain Release Merge PR / update-release-pr (push) Waiting to run
release-please / release-please (push) Waiting to run
test / test (18.x) (push) Waiting to run
test / test (20.x) (push) Waiting to run
test / test (22.x) (push) Waiting to run
Docker Image CI / build-and-push-image (push) Waiting to run
Maintain Release Merge PR / update-release-pr (push) Waiting to run
release-please / release-please (push) Waiting to run
test / test (18.x) (push) Waiting to run
test / test (20.x) (push) Waiting to run
test / test (22.x) (push) Waiting to run
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
const { DB_READ } = require("../../services/database/consts");
|
||||
const { Context } = require("../../util/context");
|
||||
const { NodeUIDSelector } = require("../node/selectors");
|
||||
const { HLFilesystemOperation } = require("./definitions");
|
||||
|
||||
class HLNameSearch extends HLFilesystemOperation {
|
||||
async _run () {
|
||||
let { actor, term } = this.values;
|
||||
const services = Context.get('services');
|
||||
const svc_fs = services.get('filesystem');
|
||||
const db = services.get('database')
|
||||
.get(DB_READ, 'fs.namesearch');
|
||||
|
||||
term = term.replace(/%/g, '');
|
||||
term = '%' + term + '%';
|
||||
|
||||
// Only user actors can do this, because the permission
|
||||
// system would otherwise slow things down
|
||||
if ( ! actor.type.user ) return [];
|
||||
|
||||
const results = await db.read(
|
||||
`SELECT uuid FROM fsentries WHERE name LIKE ? AND ` +
|
||||
`user_id = ?`,
|
||||
[term, actor.type.user.id]
|
||||
);
|
||||
|
||||
const uuids = results.map(v => v.uuid);
|
||||
|
||||
const fsnodes = await Promise.all(uuids.map(async uuid => {
|
||||
return await svc_fs.node(new NodeUIDSelector(uuid));
|
||||
}));
|
||||
|
||||
return Promise.all(fsnodes.map(async fsnode => {
|
||||
return await fsnode.getSafeEntry();
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
HLNameSearch,
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
const eggspress = require("../../api/eggspress");
|
||||
const { HLNameSearch } = require("../../filesystem/hl_operations/hl_name_search");
|
||||
const { subdomain } = require("../../helpers");
|
||||
const verified = require("../../middleware/verified");
|
||||
|
||||
module.exports = eggspress('/search', {
|
||||
subdomain: 'api',
|
||||
auth2: true,
|
||||
verified: true,
|
||||
fs: true,
|
||||
json: true,
|
||||
allowedMethods: ['POST'],
|
||||
}, async (req, res, next) => {
|
||||
const hl_name_search = new HLNameSearch();
|
||||
const result = await hl_name_search.run({
|
||||
actor: req.actor,
|
||||
term: req.body.text,
|
||||
});
|
||||
res.send(result);
|
||||
});
|
||||
@@ -38,6 +38,8 @@ class FilesystemAPIService extends BaseService {
|
||||
app.use(require('../routers/filesystem_api/copy'))
|
||||
app.use(require('../routers/filesystem_api/move'))
|
||||
app.use(require('../routers/filesystem_api/rename'))
|
||||
|
||||
app.use(require('../routers/filesystem_api/search'))
|
||||
|
||||
// v1
|
||||
app.use(require('../routers/writeFile'))
|
||||
|
||||
Reference in New Issue
Block a user