Compare commits
5 Commits
7acd546481
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
808e848561 | ||
|
|
491a1a3a4f | ||
|
|
da3aad8713 | ||
|
|
9e6397f038 | ||
|
|
bdda2bcb8d |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1 +1,3 @@
|
|||||||
cryptopad.db
|
cryptopad.db
|
||||||
|
node_modules
|
||||||
|
.wrangler
|
||||||
|
|||||||
1
d1setup.sql
Normal file
1
d1setup.sql
Normal file
@@ -0,0 +1 @@
|
|||||||
|
CREATE TABLE data (k BLOB, v BLOB, PRIMARY KEY (`k`));
|
||||||
23
functions/dump/[dump].js
Normal file
23
functions/dump/[dump].js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
export async function onRequest(context) {
|
||||||
|
if (context.params.dump !== context.env.DUMP_KEY) {
|
||||||
|
return new Response("Wrong key");
|
||||||
|
}
|
||||||
|
const db = context.env.cryptopad;
|
||||||
|
console.log(db)
|
||||||
|
let accum = []
|
||||||
|
let cursor = undefined;
|
||||||
|
|
||||||
|
do {
|
||||||
|
const listResult = await db.list({cursor});
|
||||||
|
cursor = listResult.cursor;
|
||||||
|
accum = accum.concat(listResult.keys.map(x => x.name));
|
||||||
|
} while (cursor !== undefined);
|
||||||
|
|
||||||
|
const results = await Promise.all(accum.map(async x => ({key: x, value: await db.get(x)})));
|
||||||
|
return new Response(JSON.stringify(results), {
|
||||||
|
status: 200,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/octet-stream'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
22
functions/storage/[[storage]].js
Normal file
22
functions/storage/[[storage]].js
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
export async function onRequest(context) {
|
||||||
|
const db = context.env.cryptopad;
|
||||||
|
if (context.params.storage[0] == "delete") {
|
||||||
|
const deleteReq = context.params.storage[1];
|
||||||
|
await db.delete(deleteReq);
|
||||||
|
return new Response();
|
||||||
|
}
|
||||||
|
const key = context.params.storage[0];
|
||||||
|
console.log(context);
|
||||||
|
if (context.request.method == "POST") {
|
||||||
|
const formData = await context.request.formData();
|
||||||
|
const value = formData.get("value");
|
||||||
|
console.log("Inserting", key, value);
|
||||||
|
// this doesn't use numbered parameters because miniflare behaves differently because better-sqlite3 doesn't handled numbered params well
|
||||||
|
// CF really needs named support and better-sqlite3 really needs to fix this
|
||||||
|
await db.put(key, value);
|
||||||
|
|
||||||
|
return new Response();
|
||||||
|
}
|
||||||
|
const value = await db.get(key);
|
||||||
|
return new Response(JSON.stringify(value));
|
||||||
|
}
|
||||||
16
migrate.py
Normal file
16
migrate.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import anydbm
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
data = anydbm.open("cryptopad.db", 'c');
|
||||||
|
|
||||||
|
con = sqlite3.connect("my.db")
|
||||||
|
con.text_factory = str
|
||||||
|
con.execute("CREATE TABLE data (k BLOB, v BLOB, PRIMARY KEY (`k`))")
|
||||||
|
|
||||||
|
cur = con.cursor()
|
||||||
|
|
||||||
|
for k,v in data.iteritems():
|
||||||
|
print k
|
||||||
|
cur.execute("INSERT INTO data VALUES (?,?)", [k,v])
|
||||||
|
|
||||||
|
con.commit()
|
||||||
9191
package-lock.json
generated
Normal file
9191
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
14
package.json
Normal file
14
package.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "cryptopad",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"devDependencies": {
|
||||||
|
"better-sqlite3": "^8.0.1",
|
||||||
|
"jest": "^29.5.0",
|
||||||
|
"wrangler": "3.66.0"
|
||||||
|
},
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"start": "wrangler pages dev static --d1=D1DB --persist",
|
||||||
|
"deploy": "wrangler pages publish static --project-name cryptopad"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,7 +29,7 @@ def mystatic(filepath):
|
|||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
return bottle.static_file("cryptopad.html", root='static')
|
return bottle.static_file("index.html", root='static')
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
bottle.debug(True)
|
bottle.debug(True)
|
||||||
|
|||||||
14
wrangler.toml
Normal file
14
wrangler.toml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
name = "cryptopad"
|
||||||
|
compatibility_date = "2023-03-15"
|
||||||
|
|
||||||
|
[vars]
|
||||||
|
DUMP_KEY = "dump"
|
||||||
|
|
||||||
|
[[ d1_databases ]]
|
||||||
|
binding = "D1DB"
|
||||||
|
database_name = "cryptopad"
|
||||||
|
database_id = "17080b9e-80c5-4253-8e7c-451ece72ed42"
|
||||||
|
|
||||||
|
[[kv_namespaces]]
|
||||||
|
binding = "cryptopad"
|
||||||
|
id = "f3899275342e429987dc34d37100b5b5"
|
||||||
Reference in New Issue
Block a user