mirror of
https://github.com/cupcakearmy/cryptgeon.git
synced 2024-12-23 00:36:28 +00:00
Compare commits
21 Commits
d7e5a34b14
...
2bff6a37db
Author | SHA1 | Date | |
---|---|---|---|
2bff6a37db | |||
f8223dfc62 | |||
063d073c27 | |||
ac32b97383 | |||
9c9c23d958 | |||
92893a5b2d | |||
ac68f4a540 | |||
83b2fa5372 | |||
3c86f3f3be | |||
80e64ad207 | |||
a5809c216c | |||
fb95a68b0d | |||
b43b802221 | |||
2e89007c83 | |||
fdc2722fb9 | |||
6da28a701e | |||
e6d1e0f44a | |||
6000553b95 | |||
85204776d7 | |||
c2bfe9dd0d | |||
b05841a562 |
9
.github/workflows/release.yml
vendored
9
.github/workflows/release.yml
vendored
@ -12,15 +12,22 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- uses: pnpm/action-setup@v2
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
|
cache: 'pnpm'
|
||||||
node-version-file: '.nvmrc'
|
node-version-file: '.nvmrc'
|
||||||
- uses: pnpm/action-setup@v2
|
registry-url: 'https://registry.npmjs.org'
|
||||||
|
|
||||||
- run: |
|
- run: |
|
||||||
pnpm install --frozen-lockfile
|
pnpm install --frozen-lockfile
|
||||||
pnpm run build
|
pnpm run build
|
||||||
|
|
||||||
|
- run: npm publish
|
||||||
|
working-directory: ./packages/cli
|
||||||
|
env:
|
||||||
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
|
|
||||||
docker:
|
docker:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
3
.github/workflows/test.yaml
vendored
3
.github/workflows/test.yaml
vendored
@ -13,10 +13,11 @@ jobs:
|
|||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
# Node
|
# Node
|
||||||
|
- uses: pnpm/action-setup@v2
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
|
cache: 'pnpm'
|
||||||
node-version-file: '.nvmrc'
|
node-version-file: '.nvmrc'
|
||||||
- uses: pnpm/action-setup@v2
|
|
||||||
|
|
||||||
# Docker
|
# Docker
|
||||||
- uses: docker/setup-qemu-action@v2
|
- uses: docker/setup-qemu-action@v2
|
||||||
|
593
Cryptgeon.postman_collection.json
Normal file
593
Cryptgeon.postman_collection.json
Normal file
@ -0,0 +1,593 @@
|
|||||||
|
{
|
||||||
|
"info": {
|
||||||
|
"_postman_id": "52d9e661-2d99-47f8-b09a-40b6a1c0b364",
|
||||||
|
"name": "Cryptgeon",
|
||||||
|
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
|
||||||
|
},
|
||||||
|
"item": [
|
||||||
|
{
|
||||||
|
"name": "Notes",
|
||||||
|
"item": [
|
||||||
|
{
|
||||||
|
"name": "Preview",
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"header": [],
|
||||||
|
"url": {
|
||||||
|
"raw": "{{BASE}}/notes/:id",
|
||||||
|
"host": [
|
||||||
|
"{{BASE}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"notes",
|
||||||
|
":id"
|
||||||
|
],
|
||||||
|
"variable": [
|
||||||
|
{
|
||||||
|
"key": "id",
|
||||||
|
"value": "{{NOTE_ID}}",
|
||||||
|
"description": "Id of the Note"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"description": "This endpoint is to query wether a note exists, without actually opening it. No view limits are used here, as contents of the note are not available, only the `meta` field is returned, which is public."
|
||||||
|
},
|
||||||
|
"response": [
|
||||||
|
{
|
||||||
|
"name": "200",
|
||||||
|
"originalRequest": {
|
||||||
|
"method": "GET",
|
||||||
|
"header": [],
|
||||||
|
"url": {
|
||||||
|
"raw": "{{BASE}}/notes/:id",
|
||||||
|
"host": [
|
||||||
|
"{{BASE}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"notes",
|
||||||
|
":id"
|
||||||
|
],
|
||||||
|
"variable": [
|
||||||
|
{
|
||||||
|
"key": "id",
|
||||||
|
"value": "{{NOTE_ID}}",
|
||||||
|
"description": "Id of the Note"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"status": "OK",
|
||||||
|
"code": 200,
|
||||||
|
"_postman_previewlanguage": "json",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "transfer-encoding",
|
||||||
|
"value": "chunked"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "connection",
|
||||||
|
"value": "close"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "content-type",
|
||||||
|
"value": "application/json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "content-encoding",
|
||||||
|
"value": "gzip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "vary",
|
||||||
|
"value": "accept-encoding"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "date",
|
||||||
|
"value": "Tue, 23 May 2023 05:24:29 GMT"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"cookie": [],
|
||||||
|
"body": "{}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "404",
|
||||||
|
"originalRequest": {
|
||||||
|
"method": "GET",
|
||||||
|
"header": [],
|
||||||
|
"url": {
|
||||||
|
"raw": "{{BASE}}/notes/:id",
|
||||||
|
"host": [
|
||||||
|
"{{BASE}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"notes",
|
||||||
|
":id"
|
||||||
|
],
|
||||||
|
"variable": [
|
||||||
|
{
|
||||||
|
"key": "id",
|
||||||
|
"value": "{{NOTE_ID}}",
|
||||||
|
"description": "Id of the Note"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"status": "Not Found",
|
||||||
|
"code": 404,
|
||||||
|
"_postman_previewlanguage": "plain",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "transfer-encoding",
|
||||||
|
"value": "chunked"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "connection",
|
||||||
|
"value": "close"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "vary",
|
||||||
|
"value": "accept-encoding"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "content-encoding",
|
||||||
|
"value": "gzip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "date",
|
||||||
|
"value": "Tue, 23 May 2023 05:25:26 GMT"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"cookie": [],
|
||||||
|
"body": null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Create",
|
||||||
|
"event": [
|
||||||
|
{
|
||||||
|
"listen": "test",
|
||||||
|
"script": {
|
||||||
|
"exec": [
|
||||||
|
"const jsonData = pm.response.json();",
|
||||||
|
"pm.collectionVariables.set('NOTE_ID', jsonData.id)",
|
||||||
|
""
|
||||||
|
],
|
||||||
|
"type": "text/javascript"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"request": {
|
||||||
|
"method": "POST",
|
||||||
|
"header": [],
|
||||||
|
"body": {
|
||||||
|
"mode": "raw",
|
||||||
|
"raw": "{\n \"contents\": \"Some encrypted content\",\n \"views\": 1,\n \"meta\": \"{\\\"type\\\":\\\"text\\\"}\"\n}",
|
||||||
|
"options": {
|
||||||
|
"raw": {
|
||||||
|
"language": "json"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
"raw": "{{BASE}}/notes/",
|
||||||
|
"host": [
|
||||||
|
"{{BASE}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"notes",
|
||||||
|
""
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": [
|
||||||
|
{
|
||||||
|
"name": "Simple",
|
||||||
|
"originalRequest": {
|
||||||
|
"method": "POST",
|
||||||
|
"header": [],
|
||||||
|
"body": {
|
||||||
|
"mode": "raw",
|
||||||
|
"raw": "{\n \"contents\": \"Some encrypted content\",\n \"views\": 1,\n \"meta\": \"{\\\"type\\\":\\\"text\\\"}\"\n}",
|
||||||
|
"options": {
|
||||||
|
"raw": {
|
||||||
|
"language": "json"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
"raw": "{{BASE}}/notes/",
|
||||||
|
"host": [
|
||||||
|
"{{BASE}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"notes",
|
||||||
|
""
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"status": "OK",
|
||||||
|
"code": 200,
|
||||||
|
"_postman_previewlanguage": "json",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "transfer-encoding",
|
||||||
|
"value": "chunked"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "connection",
|
||||||
|
"value": "close"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "content-encoding",
|
||||||
|
"value": "gzip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "content-type",
|
||||||
|
"value": "application/json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "vary",
|
||||||
|
"value": "accept-encoding"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "date",
|
||||||
|
"value": "Tue, 23 May 2023 05:31:54 GMT"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"cookie": [],
|
||||||
|
"body": "{\n \"id\": \"1QeEWDQbQY9dOo8cDDQjykaEjouqugTR6A78sjgn4VMv\"\n}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "5 Minutes",
|
||||||
|
"originalRequest": {
|
||||||
|
"method": "POST",
|
||||||
|
"header": [],
|
||||||
|
"body": {
|
||||||
|
"mode": "raw",
|
||||||
|
"raw": "{\n \"contents\": \"Some encrypted content\",\n \"expiration\": 5,\n \"meta\": \"{\\\"type\\\":\\\"text\\\"}\"\n}",
|
||||||
|
"options": {
|
||||||
|
"raw": {
|
||||||
|
"language": "json"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
"raw": "{{BASE}}/notes/",
|
||||||
|
"host": [
|
||||||
|
"{{BASE}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"notes",
|
||||||
|
""
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"status": "OK",
|
||||||
|
"code": 200,
|
||||||
|
"_postman_previewlanguage": "json",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "transfer-encoding",
|
||||||
|
"value": "chunked"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "connection",
|
||||||
|
"value": "close"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "content-encoding",
|
||||||
|
"value": "gzip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "content-type",
|
||||||
|
"value": "application/json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "vary",
|
||||||
|
"value": "accept-encoding"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "date",
|
||||||
|
"value": "Tue, 23 May 2023 05:31:54 GMT"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"cookie": [],
|
||||||
|
"body": "{\n \"id\": \"1QeEWDQbQY9dOo8cDDQjykaEjouqugTR6A78sjgn4VMv\"\n}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "3 Views",
|
||||||
|
"originalRequest": {
|
||||||
|
"method": "POST",
|
||||||
|
"header": [],
|
||||||
|
"body": {
|
||||||
|
"mode": "raw",
|
||||||
|
"raw": "{\n \"contents\": \"Some encrypted content\",\n \"views\": 3,\n \"meta\": \"{\\\"type\\\":\\\"text\\\"}\"\n}",
|
||||||
|
"options": {
|
||||||
|
"raw": {
|
||||||
|
"language": "json"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
"raw": "{{BASE}}/notes/",
|
||||||
|
"host": [
|
||||||
|
"{{BASE}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"notes",
|
||||||
|
""
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"status": "OK",
|
||||||
|
"code": 200,
|
||||||
|
"_postman_previewlanguage": "json",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "transfer-encoding",
|
||||||
|
"value": "chunked"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "connection",
|
||||||
|
"value": "close"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "content-encoding",
|
||||||
|
"value": "gzip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "content-type",
|
||||||
|
"value": "application/json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "vary",
|
||||||
|
"value": "accept-encoding"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "date",
|
||||||
|
"value": "Tue, 23 May 2023 05:31:54 GMT"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"cookie": [],
|
||||||
|
"body": "{\n \"id\": \"1QeEWDQbQY9dOo8cDDQjykaEjouqugTR6A78sjgn4VMv\"\n}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Read",
|
||||||
|
"request": {
|
||||||
|
"method": "DELETE",
|
||||||
|
"header": [],
|
||||||
|
"url": {
|
||||||
|
"raw": "{{BASE}}/notes/:id",
|
||||||
|
"host": [
|
||||||
|
"{{BASE}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"notes",
|
||||||
|
":id"
|
||||||
|
],
|
||||||
|
"variable": [
|
||||||
|
{
|
||||||
|
"key": "id",
|
||||||
|
"value": "{{NOTE_ID}}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"description": "This endpoint gets the actual contents of a note. It's a `DELETE` endpoint, es it decreases the `view` counter, and deletes the note if `0` is reached."
|
||||||
|
},
|
||||||
|
"response": [
|
||||||
|
{
|
||||||
|
"name": "200",
|
||||||
|
"originalRequest": {
|
||||||
|
"method": "DELETE",
|
||||||
|
"header": [],
|
||||||
|
"url": {
|
||||||
|
"raw": "{{BASE}}/notes/:id",
|
||||||
|
"host": [
|
||||||
|
"{{BASE}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"notes",
|
||||||
|
":id"
|
||||||
|
],
|
||||||
|
"variable": [
|
||||||
|
{
|
||||||
|
"key": "id",
|
||||||
|
"value": "{{NOTE_ID}}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"status": "OK",
|
||||||
|
"code": 200,
|
||||||
|
"_postman_previewlanguage": "json",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "transfer-encoding",
|
||||||
|
"value": "chunked"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "connection",
|
||||||
|
"value": "close"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "content-type",
|
||||||
|
"value": "application/json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "vary",
|
||||||
|
"value": "accept-encoding"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "content-encoding",
|
||||||
|
"value": "gzip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "date",
|
||||||
|
"value": "Tue, 23 May 2023 05:59:07 GMT"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"cookie": [],
|
||||||
|
"body": "{\n \"meta\": \"{\\\"type\\\":\\\"text\\\"}\",\n \"contents\": \"Some encrypted content\"\n}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "404",
|
||||||
|
"originalRequest": {
|
||||||
|
"method": "DELETE",
|
||||||
|
"header": [],
|
||||||
|
"url": {
|
||||||
|
"raw": "{{BASE}}/notes/:id",
|
||||||
|
"host": [
|
||||||
|
"{{BASE}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"notes",
|
||||||
|
":id"
|
||||||
|
],
|
||||||
|
"variable": [
|
||||||
|
{
|
||||||
|
"key": "id",
|
||||||
|
"value": "{{NOTE_ID}}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"status": "Not Found",
|
||||||
|
"code": 404,
|
||||||
|
"_postman_previewlanguage": "plain",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "transfer-encoding",
|
||||||
|
"value": "chunked"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "connection",
|
||||||
|
"value": "close"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "vary",
|
||||||
|
"value": "accept-encoding"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "content-encoding",
|
||||||
|
"value": "gzip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "date",
|
||||||
|
"value": "Tue, 23 May 2023 05:59:15 GMT"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"cookie": [],
|
||||||
|
"body": null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Status",
|
||||||
|
"item": [
|
||||||
|
{
|
||||||
|
"name": "Get",
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"header": [],
|
||||||
|
"url": {
|
||||||
|
"raw": "{{BASE}}/status/",
|
||||||
|
"host": [
|
||||||
|
"{{BASE}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"status",
|
||||||
|
""
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": [
|
||||||
|
{
|
||||||
|
"name": "200",
|
||||||
|
"originalRequest": {
|
||||||
|
"method": "GET",
|
||||||
|
"header": [],
|
||||||
|
"url": {
|
||||||
|
"raw": "{{BASE}}/status/",
|
||||||
|
"host": [
|
||||||
|
"{{BASE}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"status",
|
||||||
|
""
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"status": "OK",
|
||||||
|
"code": 200,
|
||||||
|
"_postman_previewlanguage": "json",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "transfer-encoding",
|
||||||
|
"value": "chunked"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "connection",
|
||||||
|
"value": "close"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "content-encoding",
|
||||||
|
"value": "gzip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "vary",
|
||||||
|
"value": "accept-encoding"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "content-type",
|
||||||
|
"value": "application/json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "date",
|
||||||
|
"value": "Tue, 23 May 2023 05:56:45 GMT"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"cookie": [],
|
||||||
|
"body": "{\n \"version\": \"2.3.0-beta.4\",\n \"max_size\": 10485760,\n \"max_views\": 100,\n \"max_expiration\": 360,\n \"allow_advanced\": true,\n \"theme_image\": \"\",\n \"theme_text\": \"\",\n \"theme_page_title\": \"\",\n \"theme_favicon\": \"\"\n}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"event": [
|
||||||
|
{
|
||||||
|
"listen": "prerequest",
|
||||||
|
"script": {
|
||||||
|
"type": "text/javascript",
|
||||||
|
"exec": [
|
||||||
|
""
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"listen": "test",
|
||||||
|
"script": {
|
||||||
|
"type": "text/javascript",
|
||||||
|
"exec": [
|
||||||
|
""
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"variable": [
|
||||||
|
{
|
||||||
|
"key": "BASE",
|
||||||
|
"value": "http://localhost:1234/api",
|
||||||
|
"type": "default"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "NOTE_ID",
|
||||||
|
"value": "",
|
||||||
|
"type": "default"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -12,6 +12,7 @@ FROM rust:1.69-alpine as backend
|
|||||||
WORKDIR /tmp
|
WORKDIR /tmp
|
||||||
RUN apk add libc-dev openssl-dev alpine-sdk
|
RUN apk add libc-dev openssl-dev alpine-sdk
|
||||||
COPY ./packages/backend/Cargo.* ./
|
COPY ./packages/backend/Cargo.* ./
|
||||||
|
ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
|
||||||
RUN cargo fetch
|
RUN cargo fetch
|
||||||
COPY ./packages/backend ./
|
COPY ./packages/backend ./
|
||||||
RUN cargo build --release
|
RUN cargo build --release
|
||||||
|
25
README.md
25
README.md
@ -18,7 +18,8 @@ EN | [简体中文](README_zh-CN.md)
|
|||||||
|
|
||||||
## About?
|
## About?
|
||||||
|
|
||||||
_cryptgeon_ is a secure, open source sharing note or file service inspired by [_PrivNote_](https://privnote.com)
|
_cryptgeon_ is a secure, open source sharing note or file service inspired by [_PrivNote_](https://privnote.com).
|
||||||
|
It includes a server, a web page and a CLI client.
|
||||||
|
|
||||||
> 🌍 If you want to translate the project feel free to reach out to me.
|
> 🌍 If you want to translate the project feel free to reach out to me.
|
||||||
>
|
>
|
||||||
@ -26,10 +27,21 @@ _cryptgeon_ is a secure, open source sharing note or file service inspired by [_
|
|||||||
|
|
||||||
## Live Service / Demo
|
## Live Service / Demo
|
||||||
|
|
||||||
|
### Web
|
||||||
|
|
||||||
Check out the live service / demo and see for yourself [cryptgeon.org](https://cryptgeon.org)
|
Check out the live service / demo and see for yourself [cryptgeon.org](https://cryptgeon.org)
|
||||||
|
|
||||||
|
### CLI
|
||||||
|
|
||||||
|
```
|
||||||
|
npx cryptgeon send text "This is a secret note"
|
||||||
|
```
|
||||||
|
|
||||||
|
For more documentation about the CLI see the [readme](./packages/cli/README.md).
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
|
- send text or files
|
||||||
- server cannot decrypt contents due to client side encryption
|
- server cannot decrypt contents due to client side encryption
|
||||||
- view or time constraints
|
- view or time constraints
|
||||||
- in memory, no persistence
|
- in memory, no persistence
|
||||||
@ -121,14 +133,13 @@ There is a [guide](https://mariushosting.com/how-to-install-cryptgeon-on-your-sy
|
|||||||
**Requirements**
|
**Requirements**
|
||||||
|
|
||||||
- `pnpm`: `>=6`
|
- `pnpm`: `>=6`
|
||||||
- `node`: `>=16`
|
- `node`: `>=18`
|
||||||
- `rust`: edition `2021`
|
- `rust`: edition `2021`
|
||||||
|
|
||||||
**Install**
|
**Install**
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pnpm install
|
pnpm install
|
||||||
pnpm --prefix frontend install
|
|
||||||
|
|
||||||
# Also you need cargo watch if you don't already have it installed.
|
# Also you need cargo watch if you don't already have it installed.
|
||||||
# https://lib.rs/crates/cargo-watch
|
# https://lib.rs/crates/cargo-watch
|
||||||
@ -148,6 +159,7 @@ Running `pnpm run dev` in the root folder will start the following things:
|
|||||||
- redis docker container
|
- redis docker container
|
||||||
- rust backend
|
- rust backend
|
||||||
- client
|
- client
|
||||||
|
- cli
|
||||||
|
|
||||||
You can see the app under [localhost:1234](http://localhost:1234).
|
You can see the app under [localhost:1234](http://localhost:1234).
|
||||||
|
|
||||||
@ -157,10 +169,7 @@ Tests are end to end tests written with Playwright.
|
|||||||
|
|
||||||
```sh
|
```sh
|
||||||
pnpm run test:prepare
|
pnpm run test:prepare
|
||||||
docker compose up redis -d
|
|
||||||
pnpm run test:server
|
|
||||||
|
|
||||||
# In another terminal.
|
|
||||||
# Use the test or test:local script. The local version only runs in one browser for quicker development.
|
# Use the test or test:local script. The local version only runs in one browser for quicker development.
|
||||||
pnpm run test:local
|
pnpm run test:local
|
||||||
```
|
```
|
||||||
@ -169,7 +178,9 @@ pnpm run test:local
|
|||||||
|
|
||||||
Please refer to the security section [here](./SECURITY.md).
|
Please refer to the security section [here](./SECURITY.md).
|
||||||
|
|
||||||
###### Attributions
|
---
|
||||||
|
|
||||||
|
_Attributions_
|
||||||
|
|
||||||
- Test data:
|
- Test data:
|
||||||
- Text for tests [Nietzsche Ipsum](https://nietzsche-ipsum.com/)
|
- Text for tests [Nietzsche Ipsum](https://nietzsche-ipsum.com/)
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"settings": {
|
"settings": {
|
||||||
"i18n-ally.localesPaths": ["packages/frontend/locales"],
|
"i18n-ally.localesPaths": ["locales"],
|
||||||
"cSpell.words": ["cryptgeon"]
|
"cSpell.words": ["cryptgeon"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"packageManager": "pnpm@8.4.0",
|
"packageManager": "pnpm@8.5.1",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev:docker": "docker-compose -f docker-compose.dev.yaml up redis",
|
"dev:docker": "docker-compose -f docker-compose.dev.yaml up redis",
|
||||||
"dev:packages": "pnpm --parallel run dev",
|
"dev:packages": "pnpm --parallel run dev",
|
||||||
@ -7,7 +7,7 @@
|
|||||||
"docker:up": "docker compose -f docker-compose.dev.yaml up",
|
"docker:up": "docker compose -f docker-compose.dev.yaml up",
|
||||||
"docker:build": "docker compose -f docker-compose.dev.yaml build",
|
"docker:build": "docker compose -f docker-compose.dev.yaml build",
|
||||||
"test": "playwright test --project chrome firefox safari",
|
"test": "playwright test --project chrome firefox safari",
|
||||||
"test:local": "playwright test --project local",
|
"test:local": "playwright test --project chrome",
|
||||||
"test:server": "run-s docker:up",
|
"test:server": "run-s docker:up",
|
||||||
"test:prepare": "run-p build docker:build",
|
"test:prepare": "run-p build docker:build",
|
||||||
"build": "pnpm run --recursive --filter=!@cryptgeon/backend build"
|
"build": "pnpm run --recursive --filter=!@cryptgeon/backend build"
|
||||||
|
2
packages/backend/Cargo.lock
generated
2
packages/backend/Cargo.lock
generated
@ -439,7 +439,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cryptgeon"
|
name = "cryptgeon"
|
||||||
version = "2.3.0-beta.4"
|
version = "2.3.0-beta.6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-files",
|
"actix-files",
|
||||||
"actix-web",
|
"actix-web",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cryptgeon"
|
name = "cryptgeon"
|
||||||
version = "2.3.0-beta.4"
|
version = "2.3.0-beta.6"
|
||||||
authors = ["cupcakearmy <hi@nicco.io>"]
|
authors = ["cupcakearmy <hi@nicco.io>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
@ -8,11 +8,6 @@ edition = "2021"
|
|||||||
name = "cryptgeon"
|
name = "cryptgeon"
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
||||||
[registries.crates-io]
|
|
||||||
protocol = "sparse"
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "4"
|
actix-web = "4"
|
||||||
actix-files = "0.6"
|
actix-files = "0.6"
|
||||||
|
@ -11,7 +11,9 @@ pub struct Note {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
pub struct NoteInfo {}
|
pub struct NoteInfo {
|
||||||
|
pub meta: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
pub struct NotePublic {
|
pub struct NotePublic {
|
||||||
|
@ -24,7 +24,7 @@ async fn one(path: web::Path<NotePath>) -> impl Responder {
|
|||||||
let note = store::get(&p.id);
|
let note = store::get(&p.id);
|
||||||
|
|
||||||
match note {
|
match note {
|
||||||
Ok(Some(_)) => HttpResponse::Ok().json(NoteInfo {}),
|
Ok(Some(n)) => HttpResponse::Ok().json(NoteInfo { meta: n.meta }),
|
||||||
Ok(None) => HttpResponse::NotFound().finish(),
|
Ok(None) => HttpResponse::NotFound().finish(),
|
||||||
Err(e) => HttpResponse::InternalServerError().body(e.to_string()),
|
Err(e) => HttpResponse::InternalServerError().body(e.to_string()),
|
||||||
}
|
}
|
||||||
|
54
packages/cli/README.md
Normal file
54
packages/cli/README.md
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
# Cryptgeon CLI
|
||||||
|
|
||||||
|
The CLI is a functionally identical way to interact with cryptgeon notes.
|
||||||
|
It supports text, files, expiration, password, etc.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npx cryptgeon
|
||||||
|
|
||||||
|
# Or install globally
|
||||||
|
npm -g install cryptgeon
|
||||||
|
cryptgeon
|
||||||
|
```
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Create simple note
|
||||||
|
cryptgeon send text "Foo bar"
|
||||||
|
|
||||||
|
# Send two files
|
||||||
|
cryptgeon send file my.pdf picture.png
|
||||||
|
|
||||||
|
# 3 views
|
||||||
|
cryptgeon send text "My message" --views 3
|
||||||
|
|
||||||
|
# 10 minutes
|
||||||
|
cryptgeon send text "My message" --minutes 10
|
||||||
|
|
||||||
|
# Custom password
|
||||||
|
cryptgeon send text "My message" --password "1337"
|
||||||
|
|
||||||
|
# Password from stdin
|
||||||
|
echo "1337" | cryptgeon send text "My message"
|
||||||
|
|
||||||
|
# Open a link
|
||||||
|
cryptgeon open https://cryptgeon.org/note/16gOIkxWjCxYNuXM8tCqMUzl...
|
||||||
|
```
|
||||||
|
|
||||||
|
## Options
|
||||||
|
|
||||||
|
### Custom server
|
||||||
|
|
||||||
|
The default server is `cryptgeon.org`, however you can use any cryptgeon server by passing the `-s` or `--server` option, or by setting the `CRYPTGEON_SERVER` environment variable.
|
||||||
|
|
||||||
|
### Password
|
||||||
|
|
||||||
|
Optionally, just like in the web ui, you can choose to use a manual password. You can do that by passing the `-p` or `--password` options, or by piping it into stdin.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
echo "my pw" | cryptgeon send text "my text"
|
||||||
|
cat pass.txt | cryptgeon send text "my text"
|
||||||
|
```
|
@ -1,6 +1,12 @@
|
|||||||
{
|
{
|
||||||
"version": "2.3.0-beta.4",
|
"version": "2.3.0-beta.6",
|
||||||
"name": "cryptgeon",
|
"name": "cryptgeon",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/cupcakearmy/cryptgeon.git",
|
||||||
|
"directory": "packages/cli"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/cupcakearmy/cryptgeon",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
|
@ -2,19 +2,38 @@ import { Adapters, get, info, setBase } from '@cryptgeon/shared'
|
|||||||
import inquirer from 'inquirer'
|
import inquirer from 'inquirer'
|
||||||
import { access, constants, writeFile } from 'node:fs/promises'
|
import { access, constants, writeFile } from 'node:fs/promises'
|
||||||
import { basename, resolve } from 'node:path'
|
import { basename, resolve } from 'node:path'
|
||||||
import { Hex } from 'occulto'
|
import { AES, Hex } from 'occulto'
|
||||||
import pretty from 'pretty-bytes'
|
import pretty from 'pretty-bytes'
|
||||||
|
|
||||||
import { exit } from './utils'
|
import { exit } from './utils'
|
||||||
|
|
||||||
export async function download(url: URL) {
|
export async function download(url: URL, all: boolean, suggestedPassword?: string) {
|
||||||
setBase(url.origin)
|
setBase(url.origin)
|
||||||
const id = url.pathname.split('/')[2]
|
const id = url.pathname.split('/')[2]
|
||||||
await info(id).catch(() => exit('Note does not exist or is expired'))
|
const preview = await info(id).catch(() => exit('Note does not exist or is expired'))
|
||||||
const note = await get(id)
|
|
||||||
|
|
||||||
const password = url.hash.slice(1)
|
// Password
|
||||||
const key = Hex.decode(password)
|
let password: string
|
||||||
|
const derivation = preview?.meta.derivation
|
||||||
|
if (derivation) {
|
||||||
|
if (suggestedPassword) {
|
||||||
|
password = suggestedPassword
|
||||||
|
} else {
|
||||||
|
const response = await inquirer.prompt([
|
||||||
|
{
|
||||||
|
type: 'password',
|
||||||
|
message: 'Note password',
|
||||||
|
name: 'password',
|
||||||
|
},
|
||||||
|
])
|
||||||
|
password = response.password
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
password = url.hash.slice(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
const key = derivation ? (await AES.derive(password, derivation))[0] : Hex.decode(password)
|
||||||
|
const note = await get(id)
|
||||||
|
|
||||||
const couldNotDecrypt = () => exit('Could not decrypt note. Probably an invalid password')
|
const couldNotDecrypt = () => exit('Could not decrypt note. Probably an invalid password')
|
||||||
switch (note.meta.type) {
|
switch (note.meta.type) {
|
||||||
@ -24,6 +43,11 @@ export async function download(url: URL) {
|
|||||||
exit('No files found in note')
|
exit('No files found in note')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let selected: typeof files
|
||||||
|
if (all) {
|
||||||
|
selected = files
|
||||||
|
} else {
|
||||||
const { names } = await inquirer.prompt([
|
const { names } = await inquirer.prompt([
|
||||||
{
|
{
|
||||||
type: 'checkbox',
|
type: 'checkbox',
|
||||||
@ -36,13 +60,12 @@ export async function download(url: URL) {
|
|||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
selected = files.filter((file) => names.includes(file.name))
|
||||||
const selected = files.filter((file) => names.includes(file.name))
|
}
|
||||||
|
|
||||||
if (!selected.length) exit('No files selected')
|
if (!selected.length) exit('No files selected')
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
files.map(async (file) => {
|
selected.map(async (file) => {
|
||||||
let filename = resolve(file.name)
|
let filename = resolve(file.name)
|
||||||
try {
|
try {
|
||||||
// If exists -> prepend timestamp to not overwrite the current file
|
// If exists -> prepend timestamp to not overwrite the current file
|
||||||
@ -53,6 +76,7 @@ export async function download(url: URL) {
|
|||||||
console.log(`Saved: ${basename(filename)}`)
|
console.log(`Saved: ${basename(filename)}`)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
break
|
break
|
||||||
case 'text':
|
case 'text':
|
||||||
const plaintext = await Adapters.Text.decrypt(note.contents, key).catch(couldNotDecrypt)
|
const plaintext = await Adapters.Text.decrypt(note.contents, key).catch(couldNotDecrypt)
|
||||||
|
@ -6,7 +6,8 @@ import prettyBytes from 'pretty-bytes'
|
|||||||
|
|
||||||
import { download } from './download.js'
|
import { download } from './download.js'
|
||||||
import { parseFile, parseNumber } from './parsers.js'
|
import { parseFile, parseNumber } from './parsers.js'
|
||||||
import { uploadFiles, uploadText } from './upload.js'
|
import { getStdin } from './stdin.js'
|
||||||
|
import { upload } from './upload.js'
|
||||||
import { exit } from './utils.js'
|
import { exit } from './utils.js'
|
||||||
|
|
||||||
const defaultServer = process.env['CRYPTGEON_SERVER'] || 'https://cryptgeon.org'
|
const defaultServer = process.env['CRYPTGEON_SERVER'] || 'https://cryptgeon.org'
|
||||||
@ -14,6 +15,7 @@ const server = new Option('-s --server <url>', 'the cryptgeon server to use').de
|
|||||||
const files = new Argument('<file...>', 'Files to be sent').argParser(parseFile)
|
const files = new Argument('<file...>', 'Files to be sent').argParser(parseFile)
|
||||||
const text = new Argument('<text>', 'Text content of the note')
|
const text = new Argument('<text>', 'Text content of the note')
|
||||||
const password = new Option('-p --password <string>', 'manually set a password')
|
const password = new Option('-p --password <string>', 'manually set a password')
|
||||||
|
const all = new Option('-a --all', 'Save all files without prompt').default(false)
|
||||||
const url = new Argument('<url>', 'The url to open')
|
const url = new Argument('<url>', 'The url to open')
|
||||||
const views = new Option('-v --views <number>', 'Amount of views before getting destroyed').argParser(parseNumber)
|
const views = new Option('-v --views <number>', 'Amount of views before getting destroyed').argParser(parseNumber)
|
||||||
const minutes = new Option('-m --minutes <number>', 'Minutes before the note expires').argParser(parseNumber)
|
const minutes = new Option('-m --minutes <number>', 'Minutes before the note expires').argParser(parseNumber)
|
||||||
@ -40,6 +42,7 @@ program.name('cryptgeon').version(version).configureHelp({ showGlobalOptions: tr
|
|||||||
|
|
||||||
program
|
program
|
||||||
.command('info')
|
.command('info')
|
||||||
|
.description('show information about the server')
|
||||||
.addOption(server)
|
.addOption(server)
|
||||||
.action(async (options) => {
|
.action(async (options) => {
|
||||||
setBase(options.server)
|
setBase(options.server)
|
||||||
@ -54,17 +57,19 @@ program
|
|||||||
console.table(formatted)
|
console.table(formatted)
|
||||||
})
|
})
|
||||||
|
|
||||||
const send = program.command('send')
|
const send = program.command('send').description('send a note')
|
||||||
send
|
send
|
||||||
.command('file')
|
.command('file')
|
||||||
.addArgument(files)
|
.addArgument(files)
|
||||||
.addOption(server)
|
.addOption(server)
|
||||||
.addOption(views)
|
.addOption(views)
|
||||||
.addOption(minutes)
|
.addOption(minutes)
|
||||||
|
.addOption(password)
|
||||||
.action(async (files, options) => {
|
.action(async (files, options) => {
|
||||||
setBase(options.server!)
|
setBase(options.server!)
|
||||||
await checkConstrains(options)
|
await checkConstrains(options)
|
||||||
await uploadFiles(files, { views: options.views, expiration: options.minutes })
|
options.password ||= await getStdin()
|
||||||
|
await upload(files, { views: options.views, expiration: options.minutes, password: options.password })
|
||||||
})
|
})
|
||||||
send
|
send
|
||||||
.command('text')
|
.command('text')
|
||||||
@ -72,19 +77,25 @@ send
|
|||||||
.addOption(server)
|
.addOption(server)
|
||||||
.addOption(views)
|
.addOption(views)
|
||||||
.addOption(minutes)
|
.addOption(minutes)
|
||||||
|
.addOption(password)
|
||||||
.action(async (text, options) => {
|
.action(async (text, options) => {
|
||||||
setBase(options.server!)
|
setBase(options.server!)
|
||||||
await checkConstrains(options)
|
await checkConstrains(options)
|
||||||
await uploadText(text, { views: options.views, expiration: options.minutes })
|
options.password ||= await getStdin()
|
||||||
|
await upload(text, { views: options.views, expiration: options.minutes, password: options.password })
|
||||||
})
|
})
|
||||||
|
|
||||||
program
|
program
|
||||||
.command('open')
|
.command('open')
|
||||||
|
.description('open a link with text or files inside')
|
||||||
.addArgument(url)
|
.addArgument(url)
|
||||||
|
.addOption(password)
|
||||||
|
.addOption(all)
|
||||||
.action(async (note, options) => {
|
.action(async (note, options) => {
|
||||||
try {
|
try {
|
||||||
const url = new URL(note)
|
const url = new URL(note)
|
||||||
await download(url)
|
options.password ||= await getStdin()
|
||||||
|
await download(url, options.all, options.password)
|
||||||
} catch {
|
} catch {
|
||||||
exit('Invalid URL')
|
exit('Invalid URL')
|
||||||
}
|
}
|
||||||
|
24
packages/cli/src/stdin.ts
Normal file
24
packages/cli/src/stdin.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
export function getStdin(timeout: number = 10): Promise<string> {
|
||||||
|
return new Promise<string>((resolve, reject) => {
|
||||||
|
// Store the data from stdin in a buffer
|
||||||
|
let buffer = ''
|
||||||
|
let t: NodeJS.Timeout
|
||||||
|
|
||||||
|
const dataHandler = (d: Buffer) => (buffer += d.toString())
|
||||||
|
const endHandler = () => {
|
||||||
|
clearTimeout(t)
|
||||||
|
resolve(buffer.trim())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stop listening for data after the timeout, otherwise hangs indefinitely
|
||||||
|
t = setTimeout(() => {
|
||||||
|
process.stdin.removeListener('data', dataHandler)
|
||||||
|
process.stdin.removeListener('end', endHandler)
|
||||||
|
process.stdin.pause()
|
||||||
|
resolve('')
|
||||||
|
}, timeout)
|
||||||
|
|
||||||
|
process.stdin.on('data', dataHandler)
|
||||||
|
process.stdin.on('end', endHandler)
|
||||||
|
})
|
||||||
|
}
|
@ -1,29 +1,28 @@
|
|||||||
import { readFile, stat } from 'node:fs/promises'
|
import { readFile, stat } from 'node:fs/promises'
|
||||||
import { basename } from 'node:path'
|
import { basename } from 'node:path'
|
||||||
|
|
||||||
import { Adapters, BASE, create, FileDTO, Note } from '@cryptgeon/shared'
|
import { Adapters, BASE, create, FileDTO, Note, NoteMeta } from '@cryptgeon/shared'
|
||||||
import mime from 'mime'
|
import mime from 'mime'
|
||||||
import { AES, Hex, TypedArray } from 'occulto'
|
import { AES, Hex, TypedArray } from 'occulto'
|
||||||
|
|
||||||
import { exit } from './utils.js'
|
import { exit } from './utils.js'
|
||||||
|
|
||||||
type UploadOptions = Pick<Note, 'views' | 'expiration'>
|
type UploadOptions = Pick<Note, 'views' | 'expiration'> & { password?: string }
|
||||||
|
|
||||||
export async function upload(key: TypedArray, note: Note) {
|
export async function upload(input: string | string[], options: UploadOptions) {
|
||||||
try {
|
try {
|
||||||
const result = await create(note)
|
const { password, ...noteOptions } = options
|
||||||
const password = Hex.encode(key)
|
const derived = options.password ? await AES.derive(options.password) : undefined
|
||||||
const url = `${BASE}/note/${result.id}#${password}`
|
const key = derived ? derived[0] : await AES.generateKey()
|
||||||
console.log(`Note created under:\n\n${url}`)
|
|
||||||
} catch {
|
|
||||||
exit('Could not create note')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function uploadFiles(paths: string[], options: UploadOptions) {
|
let contents: string
|
||||||
const key = await AES.generateKey()
|
let type: NoteMeta['type']
|
||||||
|
if (typeof input === 'string') {
|
||||||
|
contents = await Adapters.Text.encrypt(input, key)
|
||||||
|
type = 'text'
|
||||||
|
} else {
|
||||||
const files: FileDTO[] = await Promise.all(
|
const files: FileDTO[] = await Promise.all(
|
||||||
paths.map(async (path) => {
|
input.map(async (path) => {
|
||||||
const data = new Uint8Array(await readFile(path))
|
const data = new Uint8Array(await readFile(path))
|
||||||
const stats = await stat(path)
|
const stats = await stat(path)
|
||||||
const extension = path.substring(path.indexOf('.') + 1)
|
const extension = path.substring(path.indexOf('.') + 1)
|
||||||
@ -36,13 +35,17 @@ export async function uploadFiles(paths: string[], options: UploadOptions) {
|
|||||||
} satisfies FileDTO
|
} satisfies FileDTO
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
contents = await Adapters.Files.encrypt(files, key)
|
||||||
|
type = 'file'
|
||||||
|
}
|
||||||
|
|
||||||
const contents = await Adapters.Files.encrypt(files, key)
|
// Create the actual note and upload it.
|
||||||
await upload(key, { ...options, contents, meta: { type: 'file' } })
|
const note: Note = { ...noteOptions, contents, meta: { type, derivation: derived?.[1] } }
|
||||||
}
|
const result = await create(note)
|
||||||
|
let url = `${BASE}/note/${result.id}`
|
||||||
export async function uploadText(text: string, options: UploadOptions) {
|
if (!derived) url += `#${Hex.encode(key)}`
|
||||||
const key = await AES.generateKey()
|
console.log(`Note created:\n\n${url}`)
|
||||||
const contents = await Adapters.Text.encrypt(text, key)
|
} catch {
|
||||||
await upload(key, { ...options, contents, meta: { type: 'text' } })
|
exit('Could not create note')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,8 @@
|
|||||||
"decrypting": "entschlüsselt",
|
"decrypting": "entschlüsselt",
|
||||||
"uploading": "hochladen",
|
"uploading": "hochladen",
|
||||||
"downloading": "wird heruntergeladen",
|
"downloading": "wird heruntergeladen",
|
||||||
"qr_code": "qr-code"
|
"qr_code": "qr-code",
|
||||||
|
"password": "Passwort"
|
||||||
},
|
},
|
||||||
"home": {
|
"home": {
|
||||||
"intro": "Senden Sie ganz einfach <i>vollständig verschlüsselte</i>, sichere Notizen oder Dateien mit einem Klick. Erstellen Sie einfach eine Notiz und teilen Sie den Link.",
|
"intro": "Senden Sie ganz einfach <i>vollständig verschlüsselte</i>, sichere Notizen oder Dateien mit einem Klick. Erstellen Sie einfach eine Notiz und teilen Sie den Link.",
|
||||||
@ -31,6 +32,10 @@
|
|||||||
},
|
},
|
||||||
"messages": {
|
"messages": {
|
||||||
"note_created": "notiz erstellt."
|
"note_created": "notiz erstellt."
|
||||||
|
},
|
||||||
|
"advanced": {
|
||||||
|
"explanation": "Standardmäßig wird für jede Notiz ein sicher generiertes Passwort verwendet. Sie können jedoch auch ein eigenes Kennwort wählen, das nicht in dem Link enthalten ist.",
|
||||||
|
"custom_password": "benutzerdefiniertes Passwort"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"show": {
|
"show": {
|
||||||
|
@ -16,7 +16,8 @@
|
|||||||
"decrypting": "decrypting",
|
"decrypting": "decrypting",
|
||||||
"uploading": "uploading",
|
"uploading": "uploading",
|
||||||
"downloading": "downloading",
|
"downloading": "downloading",
|
||||||
"qr_code": "qr code"
|
"qr_code": "qr code",
|
||||||
|
"password": "password"
|
||||||
},
|
},
|
||||||
"home": {
|
"home": {
|
||||||
"intro": "Easily send <i>fully encrypted</i>, secure notes or files with one click. Just create a note and share the link.",
|
"intro": "Easily send <i>fully encrypted</i>, secure notes or files with one click. Just create a note and share the link.",
|
||||||
@ -31,6 +32,10 @@
|
|||||||
},
|
},
|
||||||
"messages": {
|
"messages": {
|
||||||
"note_created": "note created."
|
"note_created": "note created."
|
||||||
|
},
|
||||||
|
"advanced": {
|
||||||
|
"explanation": "By default, a securely generated password is used for each note. You can however also choose your own password, which is not included in the link.",
|
||||||
|
"custom_password": "custom password"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"show": {
|
"show": {
|
||||||
|
@ -16,7 +16,8 @@
|
|||||||
"decrypting": "descifrando",
|
"decrypting": "descifrando",
|
||||||
"uploading": "cargando",
|
"uploading": "cargando",
|
||||||
"downloading": "descargando",
|
"downloading": "descargando",
|
||||||
"qr_code": "código qr"
|
"qr_code": "código qr",
|
||||||
|
"password": "contraseña"
|
||||||
},
|
},
|
||||||
"home": {
|
"home": {
|
||||||
"intro": "Envía fácilmente notas o archivos <i>totalmente encriptados</i> y seguros con un solo clic. Solo tienes que crear una nota y compartir el enlace.",
|
"intro": "Envía fácilmente notas o archivos <i>totalmente encriptados</i> y seguros con un solo clic. Solo tienes que crear una nota y compartir el enlace.",
|
||||||
@ -31,6 +32,10 @@
|
|||||||
},
|
},
|
||||||
"messages": {
|
"messages": {
|
||||||
"note_created": "nota creada."
|
"note_created": "nota creada."
|
||||||
|
},
|
||||||
|
"advanced": {
|
||||||
|
"explanation": "Por defecto, se utiliza una contraseña generada de forma segura para cada nota. No obstante, también puede elegir su propia contraseña, que no se incluye en el enlace.",
|
||||||
|
"custom_password": "contraseña personalizada"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"show": {
|
"show": {
|
||||||
|
@ -16,7 +16,8 @@
|
|||||||
"decrypting": "déchiffrer",
|
"decrypting": "déchiffrer",
|
||||||
"uploading": "téléchargement",
|
"uploading": "téléchargement",
|
||||||
"downloading": "téléchargement",
|
"downloading": "téléchargement",
|
||||||
"qr_code": "code qr"
|
"qr_code": "code qr",
|
||||||
|
"password": "mot de passe"
|
||||||
},
|
},
|
||||||
"home": {
|
"home": {
|
||||||
"intro": "Envoyez facilement des notes ou des fichiers <i>entièrement cryptés</i> et sécurisés en un seul clic. Il suffit de créer une note et de partager le lien.",
|
"intro": "Envoyez facilement des notes ou des fichiers <i>entièrement cryptés</i> et sécurisés en un seul clic. Il suffit de créer une note et de partager le lien.",
|
||||||
@ -31,6 +32,10 @@
|
|||||||
},
|
},
|
||||||
"messages": {
|
"messages": {
|
||||||
"note_created": "note créée."
|
"note_created": "note créée."
|
||||||
|
},
|
||||||
|
"advanced": {
|
||||||
|
"explanation": "Par défaut, un mot de passe généré de manière sécurisée est utilisé pour chaque note. Vous pouvez toutefois choisir votre propre mot de passe, qui n'est pas inclus dans le lien.",
|
||||||
|
"custom_password": "mot de passe personnalisé"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"show": {
|
"show": {
|
||||||
|
@ -16,7 +16,8 @@
|
|||||||
"decrypting": "decifrando",
|
"decrypting": "decifrando",
|
||||||
"uploading": "caricamento",
|
"uploading": "caricamento",
|
||||||
"downloading": "scaricando",
|
"downloading": "scaricando",
|
||||||
"qr_code": "codice qr"
|
"qr_code": "codice qr",
|
||||||
|
"password": "password"
|
||||||
},
|
},
|
||||||
"home": {
|
"home": {
|
||||||
"intro": "Invia facilmente note o file <i>completamente criptati</i> e sicuri con un solo clic. Basta creare una nota e condividere il link.",
|
"intro": "Invia facilmente note o file <i>completamente criptati</i> e sicuri con un solo clic. Basta creare una nota e condividere il link.",
|
||||||
@ -31,6 +32,10 @@
|
|||||||
},
|
},
|
||||||
"messages": {
|
"messages": {
|
||||||
"note_created": "nota creata."
|
"note_created": "nota creata."
|
||||||
|
},
|
||||||
|
"advanced": {
|
||||||
|
"explanation": "Per impostazione predefinita, per ogni nota viene utilizzata una password generata in modo sicuro. È tuttavia possibile scegliere la propria password, che non è inclusa nel link.",
|
||||||
|
"custom_password": "password personalizzata"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"show": {
|
"show": {
|
||||||
|
@ -16,7 +16,8 @@
|
|||||||
"decrypting": "復号化",
|
"decrypting": "復号化",
|
||||||
"uploading": "アップロード中",
|
"uploading": "アップロード中",
|
||||||
"downloading": "ダウンロード中",
|
"downloading": "ダウンロード中",
|
||||||
"qr_code": "QRコード"
|
"qr_code": "QRコード",
|
||||||
|
"password": "暗号"
|
||||||
},
|
},
|
||||||
"home": {
|
"home": {
|
||||||
"intro": "<i>完全に暗号化された</i> 、安全なメモやファイルをワンクリックで簡単に送信できます。メモを作成してリンクを共有するだけです。",
|
"intro": "<i>完全に暗号化された</i> 、安全なメモやファイルをワンクリックで簡単に送信できます。メモを作成してリンクを共有するだけです。",
|
||||||
@ -31,6 +32,10 @@
|
|||||||
},
|
},
|
||||||
"messages": {
|
"messages": {
|
||||||
"note_created": "メモが作成されました。"
|
"note_created": "メモが作成されました。"
|
||||||
|
},
|
||||||
|
"advanced": {
|
||||||
|
"explanation": "デフォルトでは、安全に生成されたパスワードが各ノートに使用されます。しかし、リンクに含まれない独自のパスワードを選択することもできます。",
|
||||||
|
"custom_password": "カスタムパスワード"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"show": {
|
"show": {
|
||||||
|
@ -16,7 +16,8 @@
|
|||||||
"decrypting": "расшифровка",
|
"decrypting": "расшифровка",
|
||||||
"uploading": "загрузка",
|
"uploading": "загрузка",
|
||||||
"downloading": "скачивание",
|
"downloading": "скачивание",
|
||||||
"qr_code": "qr код"
|
"qr_code": "qr код",
|
||||||
|
"password": "пароль"
|
||||||
},
|
},
|
||||||
"home": {
|
"home": {
|
||||||
"intro": "Легко отправляйте <i>полностью зашифрованные</i> защищенные заметки или файлы одним щелчком мыши. Просто создайте заметку и поделитесь ссылкой.",
|
"intro": "Легко отправляйте <i>полностью зашифрованные</i> защищенные заметки или файлы одним щелчком мыши. Просто создайте заметку и поделитесь ссылкой.",
|
||||||
@ -31,6 +32,10 @@
|
|||||||
},
|
},
|
||||||
"messages": {
|
"messages": {
|
||||||
"note_created": "заметка создана."
|
"note_created": "заметка создана."
|
||||||
|
},
|
||||||
|
"advanced": {
|
||||||
|
"explanation": "По умолчанию для каждой заметки используется безопасно сгенерированный пароль. Однако вы также можете выбрать свой собственный пароль, который не включен в ссылку.",
|
||||||
|
"custom_password": "пользовательский пароль"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"show": {
|
"show": {
|
||||||
|
@ -16,7 +16,8 @@
|
|||||||
"decrypting": "解密",
|
"decrypting": "解密",
|
||||||
"uploading": "上传",
|
"uploading": "上传",
|
||||||
"downloading": "下载",
|
"downloading": "下载",
|
||||||
"qr_code": "二维码"
|
"qr_code": "二维码",
|
||||||
|
"password": "密码"
|
||||||
},
|
},
|
||||||
"home": {
|
"home": {
|
||||||
"intro": "飞鸽传书,一键传输完全加密的密信或文件,阅后即焚。",
|
"intro": "飞鸽传书,一键传输完全加密的密信或文件,阅后即焚。",
|
||||||
@ -31,6 +32,10 @@
|
|||||||
},
|
},
|
||||||
"messages": {
|
"messages": {
|
||||||
"note_created": "密信创建成功。"
|
"note_created": "密信创建成功。"
|
||||||
|
},
|
||||||
|
"advanced": {
|
||||||
|
"explanation": "默认情况下,每个笔记都使用安全生成的密码。但是,您也可以选择您自己的密码,该密码未包含在链接中。",
|
||||||
|
"custom_password": "自定义密码"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"show": {
|
"show": {
|
||||||
|
@ -92,7 +92,7 @@ button {
|
|||||||
}
|
}
|
||||||
|
|
||||||
*:disabled,
|
*:disabled,
|
||||||
*[disabled='true'] {
|
.disabled {
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,3 +126,13 @@ fieldset {
|
|||||||
.tr {
|
.tr {
|
||||||
text-align: right;
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hr {
|
||||||
|
border: none;
|
||||||
|
border-bottom: 2px solid var(--ui-bg-1);
|
||||||
|
margin: 1rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
@ -8,9 +8,15 @@
|
|||||||
|
|
||||||
export let note: Note
|
export let note: Note
|
||||||
export let timeExpiration = false
|
export let timeExpiration = false
|
||||||
|
export let customPassword: string | null = null
|
||||||
|
|
||||||
|
let hasCustomPassword = false
|
||||||
|
|
||||||
|
$: if (!hasCustomPassword) customPassword = null
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="fields">
|
<div class="flex col">
|
||||||
|
<div class="flex">
|
||||||
<TextInput
|
<TextInput
|
||||||
data-testid="field-views"
|
data-testid="field-views"
|
||||||
type="number"
|
type="number"
|
||||||
@ -23,14 +29,12 @@
|
|||||||
($status && v <= $status?.max_views && v > 0) ||
|
($status && v <= $status?.max_views && v > 0) ||
|
||||||
$t('home.errors.max', { values: { n: $status?.max_views ?? 0 } })}
|
$t('home.errors.max', { values: { n: $status?.max_views ?? 0 } })}
|
||||||
/>
|
/>
|
||||||
<div class="middle-switch">
|
|
||||||
<Switch
|
<Switch
|
||||||
data-testid="switch-advanced-toggle"
|
data-testid="switch-advanced-toggle"
|
||||||
label={$t('common.mode')}
|
label={$t('common.mode')}
|
||||||
bind:value={timeExpiration}
|
bind:value={timeExpiration}
|
||||||
color={false}
|
color={false}
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
<TextInput
|
<TextInput
|
||||||
data-testid="field-expiration"
|
data-testid="field-expiration"
|
||||||
type="number"
|
type="number"
|
||||||
@ -42,14 +46,37 @@
|
|||||||
($status && v < $status?.max_expiration) ||
|
($status && v < $status?.max_expiration) ||
|
||||||
$t('home.errors.max', { values: { n: $status?.max_expiration ?? 0 } })}
|
$t('home.errors.max', { values: { n: $status?.max_expiration ?? 0 } })}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="flex">
|
||||||
|
<Switch
|
||||||
|
data-testid="custom-password"
|
||||||
|
bind:value={hasCustomPassword}
|
||||||
|
label={$t('home.advanced.custom_password')}
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
data-testid="password"
|
||||||
|
type="password"
|
||||||
|
bind:value={customPassword}
|
||||||
|
label={$t('common.password')}
|
||||||
|
disabled={!hasCustomPassword}
|
||||||
|
random
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
{$t('home.advanced.explanation')}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.middle-switch {
|
.flex {
|
||||||
margin: 0 1rem;
|
display: flex;
|
||||||
|
align-items: flex-end;
|
||||||
|
gap: 1rem;
|
||||||
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.fields {
|
.col {
|
||||||
display: flex;
|
gap: 1.5rem;
|
||||||
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<script lang="ts" context="module">
|
<script lang="ts" context="module">
|
||||||
export type NoteResult = {
|
export type NoteResult = {
|
||||||
password: string
|
|
||||||
id: string
|
id: string
|
||||||
|
password?: string
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -14,7 +14,8 @@
|
|||||||
|
|
||||||
export let result: NoteResult
|
export let result: NoteResult
|
||||||
|
|
||||||
$: url = `${window.location.origin}/note/${result.id}#${result.password}`
|
let url = `${window.location.origin}/note/${result.id}`
|
||||||
|
if (result.password) url += `#${result.password}`
|
||||||
|
|
||||||
function reset() {
|
function reset() {
|
||||||
window.location.reload()
|
window.location.reload()
|
||||||
|
@ -4,43 +4,35 @@
|
|||||||
export let color = true
|
export let color = true
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div {...$$restProps}>
|
<label {...$$restProps}>
|
||||||
<label class="switch">
|
|
||||||
<small>{label}</small>
|
<small>{label}</small>
|
||||||
<input type="checkbox" bind:checked={value} />
|
<input type="checkbox" bind:checked={value} />
|
||||||
<span class:color class="slider" />
|
<span class:color class="slider" />
|
||||||
</label>
|
</label>
|
||||||
</div>
|
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
div {
|
label {
|
||||||
height: 3.75rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.switch {
|
|
||||||
position: relative;
|
position: relative;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
width: 4rem;
|
|
||||||
height: 2.5rem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.switch input {
|
label input {
|
||||||
opacity: 0;
|
display: none;
|
||||||
width: 0;
|
}
|
||||||
height: 0;
|
|
||||||
|
small {
|
||||||
|
display: block;
|
||||||
|
width: max-content;
|
||||||
}
|
}
|
||||||
|
|
||||||
.slider {
|
.slider {
|
||||||
position: absolute;
|
display: block;
|
||||||
|
width: 4rem;
|
||||||
|
height: 2.5rem;
|
||||||
|
position: relative;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
bottom: 0;
|
|
||||||
border: 2px solid var(--ui-bg-1);
|
border: 2px solid var(--ui-bg-1);
|
||||||
background-color: var(--ui-bg-0);
|
background-color: var(--ui-bg-0);
|
||||||
transition: var(--ui-anim);
|
|
||||||
transform: translateY(1.2rem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.slider:before {
|
.slider:before {
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<label>
|
<label>
|
||||||
<small disabled={$$restProps.disabled}>
|
<small class:disabled={$$restProps.disabled}>
|
||||||
{label}
|
{label}
|
||||||
{#if valid !== true}
|
{#if valid !== true}
|
||||||
<span class="error-text">{valid}</span>
|
<span class="error-text">{valid}</span>
|
||||||
@ -54,6 +54,7 @@
|
|||||||
label {
|
label {
|
||||||
position: relative;
|
position: relative;
|
||||||
display: block;
|
display: block;
|
||||||
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
label > small {
|
label > small {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { AES, Hex } from 'occulto'
|
import { AES, Hex, Bytes } from 'occulto'
|
||||||
import { t } from 'svelte-intl-precompile'
|
import { t } from 'svelte-intl-precompile'
|
||||||
import { blur } from 'svelte/transition'
|
import { blur } from 'svelte/transition'
|
||||||
|
|
||||||
@ -27,6 +27,7 @@
|
|||||||
let advanced = false
|
let advanced = false
|
||||||
let isFile = false
|
let isFile = false
|
||||||
let timeExpiration = false
|
let timeExpiration = false
|
||||||
|
let customPassword: string | null = null
|
||||||
let description = ''
|
let description = ''
|
||||||
let loading: string | null = null
|
let loading: string | null = null
|
||||||
|
|
||||||
@ -57,13 +58,14 @@
|
|||||||
try {
|
try {
|
||||||
loading = $t('common.encrypting')
|
loading = $t('common.encrypting')
|
||||||
|
|
||||||
const key = await AES.generateKey()
|
const derived = customPassword && (await AES.derive(customPassword))
|
||||||
const password = Hex.encode(key)
|
const key = derived ? derived[0] : await AES.generateKey()
|
||||||
|
|
||||||
const data: Note = {
|
const data: Note = {
|
||||||
contents: '',
|
contents: '',
|
||||||
meta: note.meta,
|
meta: note.meta,
|
||||||
}
|
}
|
||||||
|
if (derived) data.meta.derivation = derived[1]
|
||||||
if (isFile) {
|
if (isFile) {
|
||||||
if (files.length === 0) throw new EmptyContentError()
|
if (files.length === 0) throw new EmptyContentError()
|
||||||
data.contents = await Adapters.Files.encrypt(files, key)
|
data.contents = await Adapters.Files.encrypt(files, key)
|
||||||
@ -77,8 +79,8 @@
|
|||||||
loading = $t('common.uploading')
|
loading = $t('common.uploading')
|
||||||
const response = await create(data)
|
const response = await create(data)
|
||||||
result = {
|
result = {
|
||||||
password: password,
|
|
||||||
id: response.id,
|
id: response.id,
|
||||||
|
password: customPassword ? undefined : Hex.encode(key),
|
||||||
}
|
}
|
||||||
notify.success($t('home.messages.note_created'))
|
notify.success($t('home.messages.note_created'))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -148,8 +150,8 @@
|
|||||||
|
|
||||||
{#if advanced}
|
{#if advanced}
|
||||||
<div transition:blur={{ duration: 250 }}>
|
<div transition:blur={{ duration: 250 }}>
|
||||||
<br />
|
<hr />
|
||||||
<AdvancedParameters bind:note bind:timeExpiration />
|
<AdvancedParameters bind:note bind:timeExpiration bind:customPassword />
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
right: 0;
|
right: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
background-color: var(--ui-bg-0-85);
|
background-color: var(--ui-bg-0-85);
|
||||||
|
backdrop-filter: blur(2px);
|
||||||
}
|
}
|
||||||
|
|
||||||
a {
|
a {
|
||||||
|
@ -1,30 +1,35 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Hex } from 'occulto'
|
import { AES, Hex } from 'occulto'
|
||||||
import { onMount } from 'svelte'
|
import { onMount } from 'svelte'
|
||||||
import { t } from 'svelte-intl-precompile'
|
import { t } from 'svelte-intl-precompile'
|
||||||
|
|
||||||
import Button from '$lib/ui/Button.svelte'
|
import Button from '$lib/ui/Button.svelte'
|
||||||
import Loader from '$lib/ui/Loader.svelte'
|
import Loader from '$lib/ui/Loader.svelte'
|
||||||
import ShowNote, { type DecryptedNote } from '$lib/ui/ShowNote.svelte'
|
import ShowNote, { type DecryptedNote } from '$lib/ui/ShowNote.svelte'
|
||||||
import { Adapters, get, info } from '@cryptgeon/shared'
|
import TextInput from '$lib/ui/TextInput.svelte'
|
||||||
|
import { Adapters, get, info, type NoteMeta } from '@cryptgeon/shared'
|
||||||
import type { PageData } from './$types'
|
import type { PageData } from './$types'
|
||||||
|
|
||||||
export let data: PageData
|
export let data: PageData
|
||||||
|
|
||||||
let id = data.id
|
let id = data.id
|
||||||
let password: string
|
let password: string | null = null
|
||||||
let note: DecryptedNote | null = null
|
let note: DecryptedNote | null = null
|
||||||
let exists = false
|
let exists = false
|
||||||
|
let meta: NoteMeta | null = null
|
||||||
|
|
||||||
let loading: string | null = null
|
let loading: string | null = null
|
||||||
let error: string | null = null
|
let error: string | null = null
|
||||||
|
|
||||||
|
$: valid = !!password?.length
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
// Check if note exists
|
// Check if note exists
|
||||||
try {
|
try {
|
||||||
loading = $t('common.loading')
|
loading = $t('common.loading')
|
||||||
password = window.location.hash.slice(1)
|
password = window.location.hash.slice(1)
|
||||||
await info(id)
|
const note = await info(id)
|
||||||
|
meta = note.meta
|
||||||
exists = true
|
exists = true
|
||||||
} catch {
|
} catch {
|
||||||
exists = false
|
exists = false
|
||||||
@ -38,11 +43,18 @@
|
|||||||
*/
|
*/
|
||||||
async function show() {
|
async function show() {
|
||||||
try {
|
try {
|
||||||
|
if (!valid) {
|
||||||
|
error = $t('show.errors.no_password')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load note
|
||||||
error = null
|
error = null
|
||||||
loading = $t('common.downloading')
|
loading = $t('common.downloading')
|
||||||
const data = await get(id)
|
const data = await get(id)
|
||||||
loading = $t('common.decrypting')
|
loading = $t('common.decrypting')
|
||||||
const key = Hex.decode(password)
|
const derived = meta?.derivation && (await AES.derive(password!, meta.derivation))
|
||||||
|
const key = derived ? derived[0] : Hex.decode(password!)
|
||||||
switch (data.meta.type) {
|
switch (data.meta.type) {
|
||||||
case 'text':
|
case 'text':
|
||||||
note = {
|
note = {
|
||||||
@ -77,9 +89,18 @@
|
|||||||
<form on:submit|preventDefault={show}>
|
<form on:submit|preventDefault={show}>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<p>{$t('show.explanation')}</p>
|
<p>{$t('show.explanation')}</p>
|
||||||
<Button data-testid="show-note-button" type="submit">{$t('show.show_note')}</Button>
|
{#if meta?.derivation}
|
||||||
|
<TextInput
|
||||||
|
data-testid="show-note-password"
|
||||||
|
type="password"
|
||||||
|
bind:value={password}
|
||||||
|
label={$t('common.password')}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
<Button disabled={!valid} data-testid="show-note-button" type="submit"
|
||||||
|
>{$t('show.show_note')}</Button
|
||||||
|
>
|
||||||
{#if error}
|
{#if error}
|
||||||
<br />
|
|
||||||
<p class="error-text">
|
<p class="error-text">
|
||||||
{error}
|
{error}
|
||||||
<br />
|
<br />
|
||||||
@ -97,4 +118,10 @@
|
|||||||
.loader {
|
.loader {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fieldset {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -10,7 +10,7 @@ proxy.on('error', function (err, req, res) {
|
|||||||
|
|
||||||
const server = http.createServer(function (req, res) {
|
const server = http.createServer(function (req, res) {
|
||||||
const target = req.url.startsWith('/api/') ? 'http://127.0.0.1:8000' : 'http://localhost:8001'
|
const target = req.url.startsWith('/api/') ? 'http://127.0.0.1:8000' : 'http://localhost:8001'
|
||||||
proxy.web(req, res, { target })
|
proxy.web(req, res, { target, proxyTimeout: 250, timeout: 250 })
|
||||||
})
|
})
|
||||||
server.listen(1234)
|
server.listen(1234)
|
||||||
console.log('Proxy on http://localhost:1234')
|
console.log('Proxy on http://localhost:1234')
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
import type { TypedArray } from 'occulto'
|
import type { KeyData, TypedArray } from 'occulto'
|
||||||
|
|
||||||
export type NoteMeta = { type: 'text' | 'file' }
|
export type NoteMeta = {
|
||||||
|
type: 'text' | 'file'
|
||||||
|
derivation?: KeyData
|
||||||
|
}
|
||||||
|
|
||||||
export type Note = {
|
export type Note = {
|
||||||
contents: string
|
contents: string
|
||||||
@ -8,7 +11,7 @@ export type Note = {
|
|||||||
views?: number
|
views?: number
|
||||||
expiration?: number
|
expiration?: number
|
||||||
}
|
}
|
||||||
export type NoteInfo = {}
|
export type NoteInfo = Pick<Note, 'meta'>
|
||||||
export type NotePublic = Pick<Note, 'contents' | 'meta'>
|
export type NotePublic = Pick<Note, 'contents' | 'meta'>
|
||||||
export type NoteCreate = Omit<Note, 'meta'> & { meta: string }
|
export type NoteCreate = Omit<Note, 'meta'> & { meta: string }
|
||||||
|
|
||||||
@ -71,10 +74,12 @@ export async function get(id: string): Promise<NotePublic> {
|
|||||||
method: 'delete',
|
method: 'delete',
|
||||||
})
|
})
|
||||||
const { contents, meta } = data
|
const { contents, meta } = data
|
||||||
return {
|
const note = {
|
||||||
contents,
|
contents,
|
||||||
meta: JSON.parse(meta) as NoteMeta,
|
meta: JSON.parse(meta),
|
||||||
}
|
} satisfies NotePublic
|
||||||
|
if (note.meta.derivation) note.meta.derivation.salt = new Uint8Array(Object.values(note.meta.derivation.salt))
|
||||||
|
return note
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function info(id: string): Promise<NoteInfo> {
|
export async function info(id: string): Promise<NoteInfo> {
|
||||||
@ -82,7 +87,12 @@ export async function info(id: string): Promise<NoteInfo> {
|
|||||||
url: `notes/${id}`,
|
url: `notes/${id}`,
|
||||||
method: 'get',
|
method: 'get',
|
||||||
})
|
})
|
||||||
return data
|
const { meta } = data
|
||||||
|
const note = {
|
||||||
|
meta: JSON.parse(meta),
|
||||||
|
} satisfies NoteInfo
|
||||||
|
if (note.meta.derivation) note.meta.derivation.salt = new Uint8Array(Object.values(note.meta.derivation.salt))
|
||||||
|
return note
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Status = {
|
export type Status = {
|
||||||
|
33
test/cli/file/simple.spec.ts
Normal file
33
test/cli/file/simple.spec.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import { test } from '@playwright/test'
|
||||||
|
import { basename } from 'node:path'
|
||||||
|
import { Files, getFileChecksum, rm, tmpFile } from '../../files'
|
||||||
|
import { CLI, getLinkFromCLI } from '../../utils'
|
||||||
|
|
||||||
|
test.describe('file @cli', () => {
|
||||||
|
test('simple', async ({ page }) => {
|
||||||
|
const file = await tmpFile(Files.Image)
|
||||||
|
const checksum = await getFileChecksum(file)
|
||||||
|
const note = await CLI('send', 'file', file)
|
||||||
|
const link = getLinkFromCLI(note.stdout)
|
||||||
|
await rm(file)
|
||||||
|
|
||||||
|
await CLI('open', link, '--all')
|
||||||
|
const c = await getFileChecksum(basename(file))
|
||||||
|
await rm(basename(file))
|
||||||
|
test.expect(checksum).toBe(c)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('simple with password', async ({ page }) => {
|
||||||
|
const file = await tmpFile(Files.Image)
|
||||||
|
const password = 'password'
|
||||||
|
const checksum = await getFileChecksum(file)
|
||||||
|
const note = await CLI('send', 'file', file, '--password', password)
|
||||||
|
const link = getLinkFromCLI(note.stdout)
|
||||||
|
await rm(file)
|
||||||
|
|
||||||
|
await CLI('open', link, '--all', '--password', password)
|
||||||
|
const c = await getFileChecksum(basename(file))
|
||||||
|
await rm(basename(file))
|
||||||
|
test.expect(checksum).toBe(c)
|
||||||
|
})
|
||||||
|
})
|
@ -1,13 +1,23 @@
|
|||||||
import { test } from '@playwright/test'
|
import { test } from '@playwright/test'
|
||||||
import { CLI } from '../../utils'
|
import { CLI, getLinkFromCLI } from '../../utils'
|
||||||
|
|
||||||
test.describe('text @cli', () => {
|
test.describe('text @cli', () => {
|
||||||
test('simple', async ({ page }) => {
|
test('simple', async ({ page }) => {
|
||||||
const text = `Endless prejudice endless play derive joy eternal-return selfish burying. Of decieve play pinnacle faith disgust. Spirit reason salvation burying strong of joy ascetic selfish against merciful sea truth. Ubermensch moral prejudice derive chaos mountains ubermensch justice philosophy justice ultimate joy ultimate transvaluation. Virtues convictions war ascetic eternal-return spirit. Ubermensch transvaluation noble revaluation sexuality intentions salvation endless decrepit hope noble fearful. Justice ideal ultimate snare god joy evil sexuality insofar gains oneself ideal.`
|
const text = `Endless prejudice endless play derive joy eternal-return selfish burying. Of decieve play pinnacle faith disgust. Spirit reason salvation burying strong of joy ascetic selfish against merciful sea truth. Ubermensch moral prejudice derive chaos mountains ubermensch justice philosophy justice ultimate joy ultimate transvaluation. Virtues convictions war ascetic eternal-return spirit. Ubermensch transvaluation noble revaluation sexuality intentions salvation endless decrepit hope noble fearful. Justice ideal ultimate snare god joy evil sexuality insofar gains oneself ideal.`
|
||||||
const note = await CLI('send', 'text', text)
|
const note = await CLI('send', 'text', text)
|
||||||
const link = note.stdout.trim().replace(/(.|\s)*http/g, 'http')
|
const link = getLinkFromCLI(note.stdout)
|
||||||
|
|
||||||
const retrieved = await CLI('open', link)
|
const retrieved = await CLI('open', link)
|
||||||
test.expect(retrieved.stdout.trim()).toBe(text)
|
test.expect(retrieved.stdout.trim()).toBe(text)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('simple with password', async ({ page }) => {
|
||||||
|
const text = `Endless prejudice endless play derive joy eternal-return selfish burying.`
|
||||||
|
const password = 'password'
|
||||||
|
const note = await CLI('send', 'text', text, '--password', password)
|
||||||
|
const link = getLinkFromCLI(note.stdout)
|
||||||
|
|
||||||
|
const retrieved = await CLI('open', link, '--password', password)
|
||||||
|
test.expect(retrieved.stdout.trim()).toBe(text)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
53
test/cross/file/simple.spec.ts
Normal file
53
test/cross/file/simple.spec.ts
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
import { test } from '@playwright/test'
|
||||||
|
import { CLI, checkLinkForDownload, checkLinkForText, createNote, getLinkFromCLI } from '../../utils'
|
||||||
|
import { Files, getFileChecksum, rm, tmpFile } from '../../files'
|
||||||
|
import { basename } from 'path'
|
||||||
|
|
||||||
|
const text = `Endless prejudice endless play derive joy eternal-return selfish burying. Of decieve play pinnacle faith disgust. Spirit reason salvation burying strong of joy ascetic selfish against merciful sea truth. Ubermensch moral prejudice derive chaos mountains ubermensch justice philosophy justice ultimate joy ultimate transvaluation. Virtues convictions war ascetic eternal-return spirit. Ubermensch transvaluation noble revaluation sexuality intentions salvation endless decrepit hope noble fearful. Justice ideal ultimate snare god joy evil sexuality insofar gains oneself ideal.`
|
||||||
|
const password = 'password'
|
||||||
|
|
||||||
|
test.describe('text @cross', () => {
|
||||||
|
test('cli to web', async ({ page }) => {
|
||||||
|
const file = await tmpFile(Files.Image)
|
||||||
|
const checksum = await getFileChecksum(file)
|
||||||
|
const note = await CLI('send', 'file', file)
|
||||||
|
const link = getLinkFromCLI(note.stdout)
|
||||||
|
await rm(file)
|
||||||
|
|
||||||
|
await checkLinkForDownload(page, { link, text: basename(file), checksum })
|
||||||
|
})
|
||||||
|
|
||||||
|
test('cli to web with password', async ({ page }) => {
|
||||||
|
const file = await tmpFile(Files.Image)
|
||||||
|
const checksum = await getFileChecksum(file)
|
||||||
|
const note = await CLI('send', 'file', file, '--password', password)
|
||||||
|
const link = getLinkFromCLI(note.stdout)
|
||||||
|
await rm(file)
|
||||||
|
|
||||||
|
await checkLinkForDownload(page, { link, text: basename(file), checksum, password })
|
||||||
|
})
|
||||||
|
|
||||||
|
test('web to cli', async ({ page }) => {
|
||||||
|
const files = [Files.Image]
|
||||||
|
const checksum = await getFileChecksum(files[0])
|
||||||
|
const link = await createNote(page, { files })
|
||||||
|
|
||||||
|
const filename = basename(files[0])
|
||||||
|
await CLI('open', link, '--all')
|
||||||
|
const c = await getFileChecksum(filename)
|
||||||
|
await rm(basename(filename))
|
||||||
|
test.expect(checksum).toBe(c)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('web to cli with password', async ({ page }) => {
|
||||||
|
const files = [Files.Image]
|
||||||
|
const checksum = await getFileChecksum(files[0])
|
||||||
|
const link = await createNote(page, { files, password })
|
||||||
|
|
||||||
|
const filename = basename(files[0])
|
||||||
|
await CLI('open', link, '--all', '--password', password)
|
||||||
|
const c = await getFileChecksum(filename)
|
||||||
|
await rm(basename(filename))
|
||||||
|
test.expect(checksum).toBe(c)
|
||||||
|
})
|
||||||
|
})
|
@ -1,14 +1,15 @@
|
|||||||
import { test } from '@playwright/test'
|
import { test } from '@playwright/test'
|
||||||
import { CLI, checkLinkForText, createNote } from '../../utils'
|
import { CLI, checkLinkForText, createNote, getLinkFromCLI } from '../../utils'
|
||||||
|
|
||||||
const text = `Endless prejudice endless play derive joy eternal-return selfish burying. Of decieve play pinnacle faith disgust. Spirit reason salvation burying strong of joy ascetic selfish against merciful sea truth. Ubermensch moral prejudice derive chaos mountains ubermensch justice philosophy justice ultimate joy ultimate transvaluation. Virtues convictions war ascetic eternal-return spirit. Ubermensch transvaluation noble revaluation sexuality intentions salvation endless decrepit hope noble fearful. Justice ideal ultimate snare god joy evil sexuality insofar gains oneself ideal.`
|
const text = `Endless prejudice endless play derive joy eternal-return selfish burying. Of decieve play pinnacle faith disgust. Spirit reason salvation burying strong of joy ascetic selfish against merciful sea truth. Ubermensch moral prejudice derive chaos mountains ubermensch justice philosophy justice ultimate joy ultimate transvaluation. Virtues convictions war ascetic eternal-return spirit. Ubermensch transvaluation noble revaluation sexuality intentions salvation endless decrepit hope noble fearful. Justice ideal ultimate snare god joy evil sexuality insofar gains oneself ideal.`
|
||||||
|
const password = 'password'
|
||||||
|
|
||||||
test.describe('text @cross', () => {
|
test.describe('text @cross', () => {
|
||||||
test('cli to web', async ({ page }) => {
|
test('cli to web', async ({ page }) => {
|
||||||
const note = await CLI('send', 'text', text)
|
const note = await CLI('send', 'text', text)
|
||||||
const link = note.stdout.trim().replace(/(.|\s)*http/g, 'http')
|
const link = getLinkFromCLI(note.stdout)
|
||||||
|
|
||||||
await checkLinkForText(page, link, text)
|
await checkLinkForText(page, { link, text })
|
||||||
})
|
})
|
||||||
|
|
||||||
test('web to cli', async ({ page }) => {
|
test('web to cli', async ({ page }) => {
|
||||||
@ -16,4 +17,16 @@ test.describe('text @cross', () => {
|
|||||||
const retrieved = await CLI('open', link)
|
const retrieved = await CLI('open', link)
|
||||||
test.expect(retrieved.stdout.trim()).toBe(text)
|
test.expect(retrieved.stdout.trim()).toBe(text)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('cli to web with password', async ({ page }) => {
|
||||||
|
const note = await CLI('send', 'text', text, '--password', password)
|
||||||
|
const link = getLinkFromCLI(note.stdout)
|
||||||
|
await checkLinkForText(page, { link, text, password })
|
||||||
|
})
|
||||||
|
|
||||||
|
test('web to cli with password', async ({ page }) => {
|
||||||
|
const link = await createNote(page, { text, password })
|
||||||
|
const retrieved = await CLI('open', link, '--password', password)
|
||||||
|
test.expect(retrieved.stdout.trim()).toBe(text)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
25
test/files.ts
Normal file
25
test/files.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { createHash } from 'crypto'
|
||||||
|
import { cp as cpFN, rm as rmFN } from 'fs'
|
||||||
|
import { readFile } from 'fs/promises'
|
||||||
|
import { promisify } from 'util'
|
||||||
|
|
||||||
|
export const cp = promisify(cpFN)
|
||||||
|
export const rm = promisify(rmFN)
|
||||||
|
|
||||||
|
export const Files = {
|
||||||
|
PDF: 'test/assets/AES.pdf',
|
||||||
|
Image: 'test/assets/image.jpg',
|
||||||
|
Zip: 'test/assets/Pigeons.zip',
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getFileChecksum(file: string) {
|
||||||
|
const buffer = await readFile(file)
|
||||||
|
const hash = createHash('sha3-256').update(buffer).digest('hex')
|
||||||
|
return hash
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function tmpFile(file: string) {
|
||||||
|
const name = `./tmp/${Math.random().toString(36).substring(7)}`
|
||||||
|
await cp(file, name)
|
||||||
|
return name
|
||||||
|
}
|
@ -1,19 +1,25 @@
|
|||||||
import { expect, type Page } from '@playwright/test'
|
import { expect, type Page } from '@playwright/test'
|
||||||
import { createHash } from 'crypto'
|
|
||||||
import { readFile } from 'fs/promises'
|
|
||||||
import { execFile } from 'node:child_process'
|
import { execFile } from 'node:child_process'
|
||||||
import { promisify } from 'node:util'
|
import { promisify } from 'node:util'
|
||||||
|
import { getFileChecksum } from './files'
|
||||||
|
|
||||||
const exec = promisify(execFile)
|
const exec = promisify(execFile)
|
||||||
|
|
||||||
type CreatePage = { text?: string; files?: string[]; views?: number; expiration?: number; error?: string }
|
type CreatePage = {
|
||||||
|
text?: string
|
||||||
|
files?: string[]
|
||||||
|
views?: number
|
||||||
|
expiration?: number
|
||||||
|
error?: string
|
||||||
|
password?: string
|
||||||
|
}
|
||||||
export async function createNote(page: Page, options: CreatePage): Promise<string> {
|
export async function createNote(page: Page, options: CreatePage): Promise<string> {
|
||||||
await page.goto('/')
|
await page.goto('/')
|
||||||
|
|
||||||
if (options.text) {
|
if (options.text) {
|
||||||
await page.locator('[data-testid="text-field"]').fill(options.text)
|
await page.getByTestId('text-field').fill(options.text)
|
||||||
} else if (options.files) {
|
} else if (options.files) {
|
||||||
await page.locator('[data-testid="switch-file"]').click()
|
await page.getByTestId('switch-file').click()
|
||||||
|
|
||||||
const [fileChooser] = await Promise.all([
|
const [fileChooser] = await Promise.all([
|
||||||
page.waitForEvent('filechooser'),
|
page.waitForEvent('filechooser'),
|
||||||
@ -22,13 +28,16 @@ export async function createNote(page: Page, options: CreatePage): Promise<strin
|
|||||||
await fileChooser.setFiles(options.files)
|
await fileChooser.setFiles(options.files)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.views || options.expiration || options.password) await page.getByTestId('switch-advanced').click()
|
||||||
if (options.views) {
|
if (options.views) {
|
||||||
await page.locator('[data-testid="switch-advanced"]').click()
|
await page.getByTestId('field-views').fill(options.views.toString())
|
||||||
await page.locator('[data-testid="field-views"]').fill(options.views.toString())
|
|
||||||
} else if (options.expiration) {
|
} else if (options.expiration) {
|
||||||
await page.locator('[data-testid="switch-advanced"]').click()
|
await page.getByTestId('switch-advanced-toggle').click()
|
||||||
await page.locator('[data-testid="switch-advanced-toggle"]').click()
|
await page.getByTestId('field-expiration').fill(options.expiration.toString())
|
||||||
await page.locator('[data-testid="field-expiration"]').fill(options.expiration.toString())
|
}
|
||||||
|
if (options.password) {
|
||||||
|
await page.getByTestId('custom-password').click()
|
||||||
|
await page.getByTestId('password').fill(options.password)
|
||||||
}
|
}
|
||||||
|
|
||||||
await page.locator('button:has-text("create")').click()
|
await page.locator('button:has-text("create")').click()
|
||||||
@ -37,29 +46,39 @@ export async function createNote(page: Page, options: CreatePage): Promise<strin
|
|||||||
await expect(page.locator('.error-text')).toContainText(options.error, { timeout: 60_000 })
|
await expect(page.locator('.error-text')).toContainText(options.error, { timeout: 60_000 })
|
||||||
}
|
}
|
||||||
|
|
||||||
const shareLink = await page.locator('[data-testid="share-link"]').inputValue()
|
// Return share link
|
||||||
return shareLink
|
return await page.getByTestId('share-link').inputValue()
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function checkLinkForDownload(page: Page, link: string, text: string, checksum: string) {
|
type CheckLinkBase = {
|
||||||
|
link: string
|
||||||
|
text: string
|
||||||
|
password?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function checkLinkForDownload(page: Page, options: CheckLinkBase & { checksum: string }) {
|
||||||
await page.goto('/')
|
await page.goto('/')
|
||||||
await page.goto(link)
|
await page.goto(options.link)
|
||||||
await page.locator('[data-testid="show-note-button"]').click()
|
if (options.password) await page.getByTestId('show-note-password').fill(options.password)
|
||||||
|
await page.getByTestId('show-note-button').click()
|
||||||
|
|
||||||
const [download] = await Promise.all([
|
const [download] = await Promise.all([
|
||||||
page.waitForEvent('download'),
|
page.waitForEvent('download'),
|
||||||
page.locator(`[data-testid="result"] >> text=${text}`).click(),
|
page.getByTestId(`result`).locator(`text=${options.text}`).click(),
|
||||||
])
|
])
|
||||||
const path = await download.path()
|
const path = await download.path()
|
||||||
if (!path) throw new Error('Download failed')
|
if (!path) throw new Error('Download failed')
|
||||||
const cs = await getFileChecksum(path)
|
const cs = await getFileChecksum(path)
|
||||||
await expect(cs).toBe(checksum)
|
await expect(cs).toBe(options.checksum)
|
||||||
}
|
}
|
||||||
export async function checkLinkForText(page: Page, link: string, text: string) {
|
|
||||||
|
export async function checkLinkForText(page: Page, options: CheckLinkBase) {
|
||||||
await page.goto('/')
|
await page.goto('/')
|
||||||
await page.goto(link)
|
await page.goto(options.link)
|
||||||
await page.locator('[data-testid="show-note-button"]').click()
|
if (options.password) await page.getByTestId('show-note-password').fill(options.password)
|
||||||
await expect(await page.locator('[data-testid="result"] >> .note').innerText()).toContain(text)
|
await page.getByTestId('show-note-button').click()
|
||||||
|
const text = await page.getByTestId('result').locator('.note').innerText()
|
||||||
|
await expect(text).toContain(options.text)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function checkLinkDoesNotExist(page: Page, link: string) {
|
export async function checkLinkDoesNotExist(page: Page, link: string) {
|
||||||
@ -68,12 +87,6 @@ export async function checkLinkDoesNotExist(page: Page, link: string) {
|
|||||||
await expect(page.locator('main')).toContainText('note was not found or was already deleted')
|
await expect(page.locator('main')).toContainText('note was not found or was already deleted')
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getFileChecksum(file: string) {
|
|
||||||
const buffer = await readFile(file)
|
|
||||||
const hash = createHash('sha3-256').update(buffer).digest('hex')
|
|
||||||
return hash
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function CLI(...args: string[]) {
|
export async function CLI(...args: string[]) {
|
||||||
return await exec('./packages/cli/dist/index.cjs', args, {
|
return await exec('./packages/cli/dist/index.cjs', args, {
|
||||||
env: {
|
env: {
|
||||||
@ -82,3 +95,9 @@ export async function CLI(...args: string[]) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getLinkFromCLI(output: string): string {
|
||||||
|
const match = output.match(/(https?:\/\/[^\s]+)/)
|
||||||
|
if (!match) throw new Error('No link found in CLI output')
|
||||||
|
return match[0]
|
||||||
|
}
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
export default {
|
|
||||||
PDF: 'test/assets/AES.pdf',
|
|
||||||
Image: 'test/assets/image.jpg',
|
|
||||||
Zip: 'test/assets/Pigeons.zip',
|
|
||||||
}
|
|
@ -1,13 +1,13 @@
|
|||||||
import { test } from '@playwright/test'
|
import { test } from '@playwright/test'
|
||||||
import { checkLinkForDownload, createNote, getFileChecksum } from '../../utils'
|
import { Files, getFileChecksum } from '../../files'
|
||||||
import Files from './files'
|
import { checkLinkForDownload, createNote } from '../../utils'
|
||||||
|
|
||||||
test.describe('@web', () => {
|
test.describe('@web', () => {
|
||||||
test('multiple', async ({ page }) => {
|
test('multiple', async ({ page }) => {
|
||||||
const files = [Files.PDF, Files.Image]
|
const files = [Files.PDF, Files.Image]
|
||||||
const checksums = await Promise.all(files.map(getFileChecksum))
|
const checksums = await Promise.all(files.map(getFileChecksum))
|
||||||
const link = await createNote(page, { files, views: 2 })
|
const link = await createNote(page, { files, views: 2 })
|
||||||
await checkLinkForDownload(page, link, 'image.jpg', checksums[1])
|
await checkLinkForDownload(page, { link, text: 'image.jpg', checksum: checksums[1] })
|
||||||
await checkLinkForDownload(page, link, 'AES.pdf', checksums[0])
|
await checkLinkForDownload(page, { link, text: 'AES.pdf', checksum: checksums[0] })
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import { test } from '@playwright/test'
|
import { test } from '@playwright/test'
|
||||||
import { checkLinkDoesNotExist, checkLinkForDownload, checkLinkForText, createNote, getFileChecksum } from '../../utils'
|
import { Files, getFileChecksum } from '../../files'
|
||||||
import Files from './files'
|
import { checkLinkDoesNotExist, checkLinkForDownload, checkLinkForText, createNote } from '../../utils'
|
||||||
|
|
||||||
test.describe('@web', () => {
|
test.describe('@web', () => {
|
||||||
test('simple pdf', async ({ page }) => {
|
test('simple pdf', async ({ page }) => {
|
||||||
const files = [Files.PDF]
|
const files = [Files.PDF]
|
||||||
const link = await createNote(page, { files })
|
const link = await createNote(page, { files })
|
||||||
await checkLinkForText(page, link, 'AES.pdf')
|
await checkLinkForText(page, { link, text: 'AES.pdf' })
|
||||||
await checkLinkDoesNotExist(page, link)
|
await checkLinkDoesNotExist(page, link)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -14,13 +14,21 @@ test.describe('@web', () => {
|
|||||||
const files = [Files.PDF]
|
const files = [Files.PDF]
|
||||||
const checksum = await getFileChecksum(files[0])
|
const checksum = await getFileChecksum(files[0])
|
||||||
const link = await createNote(page, { files })
|
const link = await createNote(page, { files })
|
||||||
await checkLinkForDownload(page, link, 'AES.pdf', checksum)
|
await checkLinkForDownload(page, { link, text: 'AES.pdf', checksum })
|
||||||
})
|
})
|
||||||
|
|
||||||
test('image content', async ({ page }) => {
|
test('image content', async ({ page }) => {
|
||||||
const files = [Files.Image]
|
const files = [Files.Image]
|
||||||
const checksum = await getFileChecksum(files[0])
|
const checksum = await getFileChecksum(files[0])
|
||||||
const link = await createNote(page, { files })
|
const link = await createNote(page, { files })
|
||||||
await checkLinkForDownload(page, link, 'image.jpg', checksum)
|
await checkLinkForDownload(page, { link, text: 'image.jpg', checksum })
|
||||||
|
})
|
||||||
|
|
||||||
|
test('simple pdf with password', async ({ page }) => {
|
||||||
|
const files = [Files.PDF]
|
||||||
|
const password = 'password'
|
||||||
|
const link = await createNote(page, { files, password })
|
||||||
|
await checkLinkForText(page, { link, text: 'AES.pdf', password })
|
||||||
|
await checkLinkDoesNotExist(page, link)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { test } from '@playwright/test'
|
import { test } from '@playwright/test'
|
||||||
import { createNote } from '../../utils'
|
import { createNote } from '../../utils'
|
||||||
import Files from './files'
|
import { Files } from '../../files'
|
||||||
|
|
||||||
test.describe('@web', () => {
|
test.describe('@web', () => {
|
||||||
test.skip('to big zip', async ({ page }) => {
|
test.skip('to big zip', async ({ page }) => {
|
||||||
|
@ -7,10 +7,10 @@ test.describe('@web', () => {
|
|||||||
const minutes = 1
|
const minutes = 1
|
||||||
const timeout = minutes * 60_000
|
const timeout = minutes * 60_000
|
||||||
test.setTimeout(timeout * 2)
|
test.setTimeout(timeout * 2)
|
||||||
const shareLink = await createNote(page, { text, expiration: minutes })
|
const link = await createNote(page, { text, expiration: minutes })
|
||||||
await checkLinkForText(page, shareLink, text)
|
await checkLinkForText(page, { link, text })
|
||||||
await checkLinkForText(page, shareLink, text)
|
await checkLinkForText(page, { link, text })
|
||||||
await page.waitForTimeout(timeout)
|
await page.waitForTimeout(timeout)
|
||||||
await checkLinkDoesNotExist(page, shareLink)
|
await checkLinkDoesNotExist(page, link)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -3,8 +3,15 @@ import { checkLinkForText, createNote } from '../../utils'
|
|||||||
|
|
||||||
test.describe('@web', () => {
|
test.describe('@web', () => {
|
||||||
test('simple', async ({ page }) => {
|
test('simple', async ({ page }) => {
|
||||||
const text = `Endless prejudice endless play derive joy eternal-return selfish burying. Of decieve play pinnacle faith disgust. Spirit reason salvation burying strong of joy ascetic selfish against merciful sea truth. Ubermensch moral prejudice derive chaos mountains ubermensch justice philosophy justice ultimate joy ultimate transvaluation. Virtues convictions war ascetic eternal-return spirit. Ubermensch transvaluation noble revaluation sexuality intentions salvation endless decrepit hope noble fearful. Justice ideal ultimate snare god joy evil sexuality insofar gains oneself ideal.`
|
const text = `Endless prejudice endless play derive joy eternal-return selfish burying. Of deceive play pinnacle faith disgust. Spirit reason salvation burying strong of joy ascetic selfish against merciful sea truth. Ubermensch moral prejudice derive chaos mountains ubermensch justice philosophy justice ultimate joy ultimate transvaluation. Virtues convictions war ascetic eternal-return spirit. Ubermensch transvaluation noble revaluation sexuality intentions salvation endless decrepit hope noble fearful. Justice ideal ultimate snare god joy evil sexuality insofar gains oneself ideal.`
|
||||||
const shareLink = await createNote(page, { text })
|
const link = await createNote(page, { text })
|
||||||
await checkLinkForText(page, shareLink, text)
|
await checkLinkForText(page, { link, text })
|
||||||
|
})
|
||||||
|
|
||||||
|
test('simple with password', async ({ page }) => {
|
||||||
|
const text = 'Foo bar'
|
||||||
|
const password = '123'
|
||||||
|
const shareLink = await createNote(page, { text, password })
|
||||||
|
await checkLinkForText(page, { link: shareLink, text, password })
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -4,17 +4,17 @@ import { checkLinkDoesNotExist, checkLinkForText, createNote } from '../../utils
|
|||||||
test.describe('@web', () => {
|
test.describe('@web', () => {
|
||||||
test('only shown once', async ({ page }) => {
|
test('only shown once', async ({ page }) => {
|
||||||
const text = `Christian victorious reason suicide dead. Right ultimate gains god hope truth burying selfish society joy. Ultimate.`
|
const text = `Christian victorious reason suicide dead. Right ultimate gains god hope truth burying selfish society joy. Ultimate.`
|
||||||
const shareLink = await createNote(page, { text })
|
const link = await createNote(page, { text })
|
||||||
await checkLinkForText(page, shareLink, text)
|
await checkLinkForText(page, { link, text })
|
||||||
await checkLinkDoesNotExist(page, shareLink)
|
await checkLinkDoesNotExist(page, link)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('view 3 times', async ({ page }) => {
|
test('view 3 times', async ({ page }) => {
|
||||||
const text = `Justice holiest overcome fearful strong ultimate holiest christianity.`
|
const text = `Justice holiest overcome fearful strong ultimate holiest christianity.`
|
||||||
const shareLink = await createNote(page, { text, views: 3 })
|
const link = await createNote(page, { text, views: 3 })
|
||||||
await checkLinkForText(page, shareLink, text)
|
await checkLinkForText(page, { link, text })
|
||||||
await checkLinkForText(page, shareLink, text)
|
await checkLinkForText(page, { link, text })
|
||||||
await checkLinkForText(page, shareLink, text)
|
await checkLinkForText(page, { link, text })
|
||||||
await checkLinkDoesNotExist(page, shareLink)
|
await checkLinkDoesNotExist(page, link)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user