File tree 3 files changed +63
-0
lines changed
3 files changed +63
-0
lines changed Original file line number Diff line number Diff line change
1
+ const { DB_READ } = require ( "../../services/database/consts" ) ;
2
+ const { Context } = require ( "../../util/context" ) ;
3
+ const { NodeUIDSelector } = require ( "../node/selectors" ) ;
4
+ const { HLFilesystemOperation } = require ( "./definitions" ) ;
5
+
6
+ class HLNameSearch extends HLFilesystemOperation {
7
+ async _run ( ) {
8
+ let { actor, term } = this . values ;
9
+ const services = Context . get ( 'services' ) ;
10
+ const svc_fs = services . get ( 'filesystem' ) ;
11
+ const db = services . get ( 'database' )
12
+ . get ( DB_READ , 'fs.namesearch' ) ;
13
+
14
+ term = term . replace ( / % / g, '' ) ;
15
+ term = '%' + term + '%' ;
16
+
17
+ // Only user actors can do this, because the permission
18
+ // system would otherwise slow things down
19
+ if ( ! actor . type . user ) return [ ] ;
20
+
21
+ const results = await db . read (
22
+ `SELECT uuid FROM fsentries WHERE name LIKE ? AND ` +
23
+ `user_id = ?` ,
24
+ [ term , actor . type . user . id ]
25
+ ) ;
26
+
27
+ const uuids = results . map ( v => v . uuid ) ;
28
+
29
+ const fsnodes = await Promise . all ( uuids . map ( async uuid => {
30
+ return await svc_fs . node ( new NodeUIDSelector ( uuid ) ) ;
31
+ } ) ) ;
32
+
33
+ return Promise . all ( fsnodes . map ( async fsnode => {
34
+ return await fsnode . getSafeEntry ( ) ;
35
+ } ) ) ;
36
+ }
37
+ }
38
+
39
+ module . exports = {
40
+ HLNameSearch,
41
+ } ;
Original file line number Diff line number Diff line change
1
+ const eggspress = require ( "../../api/eggspress" ) ;
2
+ const { HLNameSearch } = require ( "../../filesystem/hl_operations/hl_name_search" ) ;
3
+ const { subdomain } = require ( "../../helpers" ) ;
4
+ const verified = require ( "../../middleware/verified" ) ;
5
+
6
+ module . exports = eggspress ( '/search' , {
7
+ subdomain : 'api' ,
8
+ auth2 : true ,
9
+ verified : true ,
10
+ fs : true ,
11
+ json : true ,
12
+ allowedMethods : [ 'POST' ] ,
13
+ } , async ( req , res , next ) => {
14
+ const hl_name_search = new HLNameSearch ( ) ;
15
+ const result = await hl_name_search . run ( {
16
+ actor : req . actor ,
17
+ term : req . body . text ,
18
+ } ) ;
19
+ res . send ( result ) ;
20
+ } ) ;
Original file line number Diff line number Diff line change @@ -38,6 +38,8 @@ class FilesystemAPIService extends BaseService {
38
38
app . use ( require ( '../routers/filesystem_api/copy' ) )
39
39
app . use ( require ( '../routers/filesystem_api/move' ) )
40
40
app . use ( require ( '../routers/filesystem_api/rename' ) )
41
+
42
+ app . use ( require ( '../routers/filesystem_api/search' ) )
41
43
42
44
// v1
43
45
app . use ( require ( '../routers/writeFile' ) )
You can’t perform that action at this time.
0 commit comments