Add new API endpoint to get a list of files for a given directory.
This commit is contained in:
@@ -67,13 +67,12 @@ Just push to the `main` branch.
|
||||
- [x] Files UI
|
||||
- [x] WebDav Server
|
||||
- [x] [Desktop app for selective file sync](https://github.com/bewcloud/bewcloud-desktop/releases) (`rclone` via WebDav)
|
||||
- [ ] Mobile app for offline file view (WebDav client)
|
||||
- [ ] Mobile app for offline file view (API + WebDav client)
|
||||
- [ ] Add photo auto-uplod support for mobile client
|
||||
- [ ] Add notes view support for mobile app
|
||||
- [ ] Add notes edit support for mobile app
|
||||
- [ ] Notes UI
|
||||
- [ ] Photos UI
|
||||
- [ ] Address `TODO:`s in code
|
||||
|
||||
## Where's Contacts/Calendar (CardDav/CalDav)?! Wasn't this supposed to be a core Nextcloud replacement?
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import * as $api_files_create_directory from './routes/api/files/create-director
|
||||
import * as $api_files_delete_directory from './routes/api/files/delete-directory.tsx';
|
||||
import * as $api_files_delete from './routes/api/files/delete.tsx';
|
||||
import * as $api_files_get_directories from './routes/api/files/get-directories.tsx';
|
||||
import * as $api_files_get from './routes/api/files/get.tsx';
|
||||
import * as $api_files_move_directory from './routes/api/files/move-directory.tsx';
|
||||
import * as $api_files_move from './routes/api/files/move.tsx';
|
||||
import * as $api_files_rename_directory from './routes/api/files/rename-directory.tsx';
|
||||
@@ -52,6 +53,7 @@ const manifest = {
|
||||
'./routes/api/files/delete-directory.tsx': $api_files_delete_directory,
|
||||
'./routes/api/files/delete.tsx': $api_files_delete,
|
||||
'./routes/api/files/get-directories.tsx': $api_files_get_directories,
|
||||
'./routes/api/files/get.tsx': $api_files_get,
|
||||
'./routes/api/files/move-directory.tsx': $api_files_move_directory,
|
||||
'./routes/api/files/move.tsx': $api_files_move,
|
||||
'./routes/api/files/rename-directory.tsx': $api_files_rename_directory,
|
||||
|
||||
40
routes/api/files/get.tsx
Normal file
40
routes/api/files/get.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import { Handlers } from 'fresh/server.ts';
|
||||
|
||||
import { DirectoryFile, FreshContextState } from '/lib/types.ts';
|
||||
import { getFiles } from '/lib/data/files.ts';
|
||||
|
||||
interface Data {}
|
||||
|
||||
export interface RequestBody {
|
||||
parentPath: string;
|
||||
}
|
||||
|
||||
export interface ResponseBody {
|
||||
success: boolean;
|
||||
files: DirectoryFile[];
|
||||
}
|
||||
|
||||
export const handler: Handlers<Data, FreshContextState> = {
|
||||
async POST(request, context) {
|
||||
if (!context.state.user) {
|
||||
return new Response('Unauthorized', { status: 401 });
|
||||
}
|
||||
|
||||
const requestBody = await request.clone().json() as RequestBody;
|
||||
|
||||
if (
|
||||
!requestBody.parentPath || !requestBody.parentPath.startsWith('/') || requestBody.parentPath.includes('../')
|
||||
) {
|
||||
return new Response('Bad Request', { status: 400 });
|
||||
}
|
||||
|
||||
const files = await getFiles(
|
||||
context.state.user.id,
|
||||
requestBody.parentPath,
|
||||
);
|
||||
|
||||
const responseBody: ResponseBody = { success: true, files };
|
||||
|
||||
return new Response(JSON.stringify(responseBody));
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user