-
Notifications
You must be signed in to change notification settings - Fork 18
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
Showing
27 changed files
with
500 additions
and
121 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
CALLBACK_URL=http://localhost:4000/sync | ||
CALLBACK_OBJECTS='{"excel":"Map"}' |
This file was deleted.
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
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
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
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,68 @@ | ||
import { ICollaborationProvider, DocumentItem } from '../src'; | ||
|
||
const BASE_URL = 'http://localhost:4000'; | ||
|
||
async function fetchData<T>( | ||
url: string, | ||
method: 'POST' | 'GET' | 'PUT' | 'DELETE' = 'GET', | ||
data: string | FormData = '', | ||
) { | ||
try { | ||
const result = await fetch(`${BASE_URL}${url}`, { | ||
method, | ||
body: method === 'POST' || method === 'PUT' ? data : undefined, | ||
headers: | ||
typeof data === 'string' | ||
? { | ||
'Content-Type': 'application/json', | ||
} | ||
: undefined, | ||
}); | ||
if (result.status !== 200) { | ||
return; | ||
} | ||
const res = result.json(); | ||
return res as T; | ||
} catch (error) { | ||
console.log(error); | ||
return; | ||
} | ||
} | ||
|
||
export class Provider implements ICollaborationProvider { | ||
async uploadFile( | ||
docId: string, | ||
file: File, | ||
_base64: string, | ||
): Promise<string> { | ||
const form = new FormData(); | ||
form.append('file', file); | ||
form.append('docId', docId); | ||
const res = await fetchData<{ filePath: string }>('/upload', 'POST', form); | ||
return res?.filePath ?? _base64; | ||
} | ||
downloadFile(_docId: string, filePath: string): Promise<string> { | ||
return Promise.resolve(BASE_URL + filePath); | ||
} | ||
async addDocument(id: string) { | ||
await fetchData<DocumentItem>( | ||
'/document', | ||
'POST', | ||
JSON.stringify({ name: '', id }), | ||
); | ||
} | ||
async updateDocument( | ||
id: string, | ||
data: Pick<DocumentItem, 'name' | 'content'>, | ||
): Promise<void> { | ||
await fetchData<DocumentItem>( | ||
'/document/' + id, | ||
'PUT', | ||
JSON.stringify(data), | ||
); | ||
} | ||
async getDocument(id: string): Promise<DocumentItem | undefined> { | ||
const res = await fetchData<DocumentItem>('/document/' + id); | ||
return res; | ||
} | ||
} |
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
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
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
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,11 @@ | ||
# Start | ||
|
||
```bash | ||
npm i -g pnpm | ||
pnpm i | ||
npm run dev | ||
``` | ||
|
||
## Database | ||
|
||
[SQL](./prisma/migrations/20250106130540_init/migration.sql) |
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,27 @@ | ||
{ | ||
"name": "server", | ||
"main": "index.ts", | ||
"scripts": { | ||
"dev": "npx tsx ./src/index.ts", | ||
"build": "npx tsc", | ||
"postinstall": "npx prisma migrate dev --name init" | ||
}, | ||
"devDependencies": { | ||
"@types/cors": "^2.8.17", | ||
"@types/koa": "^2.15.0", | ||
"@types/koa__cors": "^5.0.0", | ||
"@types/koa__router": "^12.0.4", | ||
"@types/node": "^22.10.5", | ||
"prisma": "^6.1.0", | ||
"ts-node": "^10.9.2", | ||
"tsx": "^4.19.2", | ||
"typescript": "^5.7.2" | ||
}, | ||
"dependencies": { | ||
"@koa/cors": "^5.0.0", | ||
"@koa/router": "^13.1.0", | ||
"@prisma/client": "^6.1.0", | ||
"koa": "^2.15.3", | ||
"koa-body": "^6.0.1" | ||
} | ||
} |
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 @@ | ||
-- CreateTable | ||
CREATE TABLE "document" ( | ||
"id" TEXT NOT NULL PRIMARY KEY, | ||
"name" TEXT, | ||
"create_time" TEXT NOT NULL, | ||
"content" TEXT | ||
); |
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,3 @@ | ||
# Please do not edit this file manually | ||
# It should be added in your version-control system (e.g., Git) | ||
provider = "sqlite" |
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,15 @@ | ||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
|
||
datasource db { | ||
provider = "sqlite" | ||
url = "file:./dev.db" | ||
} | ||
|
||
model document { | ||
id String @id | ||
name String? | ||
create_time String | ||
content String? | ||
} |
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,6 @@ | ||
import app from "./route"; | ||
|
||
const port = 4000; | ||
app.listen(port, () => { | ||
console.log(`server running on http://localhost:${port}`); | ||
}); |
Oops, something went wrong.