-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
725178d
commit 8b3af1c
Showing
4 changed files
with
76 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import ky from 'ky' | ||
import { noop } from 'lodash-es' | ||
import { FileAccessor } from './file-accessor' | ||
import { type FileSystemProvider } from './file-system-provider' | ||
|
||
export class ServerProvider implements FileSystemProvider { | ||
static getSingleton() { | ||
return new ServerProvider() | ||
} | ||
|
||
async getContent(path: string) { | ||
return await ky('/api/content', { json: { path } }).blob() | ||
} | ||
|
||
async peekContent(path: string) { | ||
return await this.getContent(path) | ||
} | ||
|
||
async getContentAndCache(path: string) { | ||
return await this.getContent(path) | ||
} | ||
|
||
// path should not start with a slash | ||
// todo: maybe needs to make it be the same as the onedrive provider | ||
async create({ file, path }: { file: Blob; path: string }) { | ||
const body = new FormData() | ||
body.append('path', path) | ||
body.append('file', file) | ||
await ky('/api/create', { body }) | ||
} | ||
|
||
// todo: not implemented yet | ||
async delete(path: string) { | ||
noop(path) | ||
await Promise.resolve(undefined) | ||
} | ||
|
||
async list(path = '') { | ||
const files = await ky('/api/create', { json: { path } }).json<any>() | ||
|
||
return files.map( | ||
(item) => | ||
new FileAccessor({ | ||
name: item.name ?? '', | ||
directory: path, | ||
type: item.type, | ||
temporaryUrl: item.temporaryUrl, | ||
fileSystemProvider: this, | ||
}), | ||
) | ||
} | ||
|
||
async peek(path: string) { | ||
noop(path) | ||
return await Promise.resolve(undefined) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Hono } from 'hono' | ||
|
||
const app = new Hono() | ||
|
||
app.get('/api/ls', (c) => c.text('Hono!')) | ||
|
||
export default app |