Skip to content

Commit

Permalink
feat: add server provider
Browse files Browse the repository at this point in the history
  • Loading branch information
arianrhodsandlot committed Jan 23, 2024
1 parent 725178d commit 8b3af1c
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"framer-motion": "10.16.16",
"github-fork-ribbon-css": "0.2.3",
"goodcodes-parser": "2.5.0",
"hono": "^3.12.6",
"i18next": "23.7.13",
"i18next-browser-languagedetector": "7.2.0",
"idb": "8.0.0",
Expand Down
14 changes: 11 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions src/core/classes/file-system-providers/server-provider.ts
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)
}
}
7 changes: 7 additions & 0 deletions src/server/app.ts
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

0 comments on commit 8b3af1c

Please sign in to comment.