Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API v1 & major refactoring: Hono, file read optimizations, and upload streaming #16

Draft
wants to merge 185 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
185 commits
Select commit Hold shift + click to select a range
f4e7dfa
api-v1: Adds initial empty files
linkability Oct 4, 2023
70591c7
api-v1: apihandler
nbitzz Oct 4, 2023
1ed1acc
api-v1: apihandler
nbitzz Oct 4, 2023
9a589d3
clear up internal libs (@Jack5079)
nbitzz Oct 4, 2023
5a84f76
IMPORTANT: readd British(🚫) joke
nbitzz Oct 4, 2023
ab61746
housekeeping
nbitzz Oct 4, 2023
0874546
Add middleware to account api-v1
linkability Oct 4, 2023
01fe79d
api-v1: add new middleware function
nbitzz Oct 4, 2023
6e6afd2
api-v1: fix middleware func
nbitzz Oct 4, 2023
503f5f3
api-v1: start work on sanitize middleware func
nbitzz Oct 4, 2023
ceac1fc
Merge branch 'api-v1' of https://github.com/nbitzz/monofile into api-v1
linkability Oct 5, 2023
36b59d1
fix: :bug: it does not import Accounts
linkability Oct 5, 2023
03c638b
assertAPI instead of noAPIAccessIf
linkability Oct 5, 2023
6b8d050
account api half done
linkability Oct 5, 2023
c51d8da
accidentally left comment in from old api
linkability Oct 5, 2023
9e83d75
api-v1: Charlie is on meth
nbitzz Oct 5, 2023
01bb468
delete your own account endpoint
linkability Oct 5, 2023
48e00b1
Merge branch 'api-v1' of https://github.com/nbitzz/monofile into api-v1
linkability Oct 5, 2023
e574438
files is not mounted to accounts
linkability Oct 5, 2023
03fa036
change nickname added to apiv1
linkability Oct 5, 2023
a1b6917
add admin password and elevate route
linkability Oct 6, 2023
d875833
http method changes and use ServeError
linkability Oct 6, 2023
4413363
fix: :bug: body is not sent in delete requests requiring a parameter
linkability Oct 6, 2023
e5b8b83
admin delete user endpoint api-v1
linkability Oct 6, 2023
3dec4d4
Remove Boolean from checks
linkability Oct 9, 2023
dbe927f
Remove Boolean from checks
linkability Oct 9, 2023
0405f89
weed smoker charlie
nbitzz Oct 11, 2023
365aace
refactor: :recycle: Use real async in file.ts, change FileUploadSetti…
Jack5079 Oct 24, 2023
b135dc7
refactor: :recycle: Use .replaceAll instead of /g
Jack5079 Oct 24, 2023
b71963a
refactor: :truck: Move preview to new file
Jack5079 Oct 24, 2023
6220cd8
refactor: :recycle: Use Vite instead of Rollup
Jack5079 Oct 24, 2023
0366c91
refactor: :recycle: Honofile.
Jack5079 Oct 24, 2023
70cad2d
Working on it..
nbitzz Oct 26, 2023
16db5c3
mihari.oyama.pictures/Tired
nbitzz Oct 27, 2023
a096a33
idk lol
nbitzz Oct 27, 2023
a761e3f
i'm gonna be honest i dont even know anymore
nbitzz Oct 28, 2023
4882a8b
g
nbitzz Oct 29, 2023
94ea40a
this code is horrible and i know it lmao
nbitzz Oct 29, 2023
f2deea4
ok time to work on client
nbitzz Oct 29, 2023
2e29d40
idk
nbitzz Oct 29, 2023
107709a
Move client to files.ts
nbitzz Nov 2, 2023
739f5b4
port readFileStream
nbitzz Nov 2, 2023
3a5327a
Port deletions
nbitzz Nov 2, 2023
dddfd9d
remove rant lmfao
nbitzz Nov 6, 2023
460df71
i have no idea if this works or not
nbitzz Nov 6, 2023
f3e9f58
i think that this should work well enough
nbitzz Nov 17, 2023
edc3e2c
i don't even know
nbitzz Nov 17, 2023
7654801
MAN FUCK YO PICKLES honk mimimimimimi honk mimimim
nbitzz Nov 19, 2023
412a117
node-fetch conversion
nbitzz Nov 30, 2023
c14ddf8
work a bit on DiscordAPI
nbitzz Nov 30, 2023
1fabc2f
clean up file updates
nbitzz Dec 5, 2023
a5964f5
drop .getFilePointer()
nbitzz Dec 6, 2023
b8d46bb
KILL DISCORD.JS JS 🚀🎉
nbitzz Dec 6, 2023
c57f4ed
start work on writeFileStream
nbitzz Dec 6, 2023
79ecb5e
whatever i'm making rin is terrible
nbitzz Dec 11, 2023
3de215e
Working on it...
nbitzz Dec 12, 2023
5fd6073
ok i'll need to figure more out later
nbitzz Dec 15, 2023
c5040e1
hwo tf am i gonna add backpressure to this i just realized
nbitzz Dec 15, 2023
37216c8
todo another rework of readfilestream yay
nbitzz Dec 23, 2023
7d18a60
OOPS
nbitzz Dec 23, 2023
fd8e143
readFileStream now respects backpressure more
nbitzz Dec 23, 2023
033295c
remove deprecated function
nbitzz Dec 23, 2023
4c77605
I have no idea if this works lol
nbitzz Dec 26, 2023
1b31ba8
add MOLLER method
nbitzz Dec 26, 2023
afbb29c
add moller
nbitzz Dec 26, 2023
8fb2a55
does anyone else have uncontrollable urges to meow
nbitzz Dec 26, 2023
b80ddd2
awh fuck it
nbitzz Dec 27, 2023
1805c63
i cant believe it took me this long to realize
nbitzz Dec 27, 2023
9a1cb3d
All of my neurons are completely fried
nbitzz Dec 27, 2023
0f9bcba
meeow! mreeow! nya!
nbitzz Dec 28, 2023
c6e9e25
this is a mess and still definitely incomplete
nbitzz Mar 1, 2024
31f95ea
unfinished but
nbitzz Mar 1, 2024
0621f55
i think i might have been stupid
nbitzz Mar 1, 2024
0a78c19
uhhh idk
nbitzz Mar 1, 2024
daca021
almost works
nbitzz Mar 2, 2024
549f7de
IT.S DONE FUCK
nbitzz Mar 4, 2024
25afbf4
Server now runs
nbitzz Mar 4, 2024
fd44416
And that's probably it
nbitzz Mar 4, 2024
971ee31
this hurts
nbitzz Mar 4, 2024
5d3fb29
still incomplete and probably bad
nbitzz Mar 4, 2024
53c9c5f
fix: :bug: Make cookie apply for the whole site instead of just /auth/
Jack5079 Mar 4, 2024
41dc623
back to formidable
nbitzz Mar 5, 2024
7d622a4
Oh that's actually done
nbitzz Mar 5, 2024
840fb2a
oh its just requestTimeout.
nbitzz Mar 5, 2024
fb720bc
port clone route
nbitzz Mar 5, 2024
9ff8f64
thtas enough cleanup actually fuck you
nbitzz Mar 5, 2024
dcf35f8
Cool i have stuf to fix :3
nbitzz Mar 5, 2024
e92f5ea
Oh shit this doesn't respect backpressure
nbitzz Mar 5, 2024
cad72fa
refactor: :label: Remove targetGuild from config typings
Jack5079 Mar 5, 2024
3bedc21
fix bulk deletions in deleteMessages
nbitzz Mar 6, 2024
4fdada5
i have a hunch hono's streaming api buffers
nbitzz Mar 6, 2024
70eace9
uhhh...? can't test; not home. prolly doesn't work @Jack5079
nbitzz Mar 6, 2024
7df1c81
My goddd you konw what that owrks well enough
nbitzz Mar 7, 2024
92e330d
Wow i am. stupid okay
nbitzz Mar 7, 2024
cdcc1f0
Graaahhh
nbitzz Mar 7, 2024
c87316c
grahh how am i going to do secondary authenticatino for the delete /u…
nbitzz Mar 7, 2024
7560771
feat: cookie persistence
Jack5079 Mar 8, 2024
687e083
refactor: :alien: Remove v0 CSS API and migrate client to v1 CSS API
Jack5079 Mar 8, 2024
11e0494
refactor: :alien: Same but with embedSize and embedColor
Jack5079 Mar 8, 2024
10b4e2b
hwhw
nbitzz Mar 8, 2024
dc111da
workign on it
nbitzz Mar 8, 2024
e9df285
Ahhhhh im gonna figure this out when i get homeee
nbitzz Mar 8, 2024
b04414a
alright that's enough for now i'm gonna go eat
nbitzz Mar 9, 2024
e624e19
before i forget,
nbitzz Mar 9, 2024
86f5727
Okay that's enough for now
nbitzz Mar 9, 2024
00fcf45
hhhh
nbitzz Mar 9, 2024
d0ee458
Merge branch 'main' into api-v1
nbitzz Mar 9, 2024
555fbd2
Apparently we require Node 20 now, so here's Node 20
nbitzz Mar 9, 2024
d6dd753
Quick fix
nbitzz Mar 9, 2024
490098f
Fix favicon
Jack5079 Mar 10, 2024
8f1b1ad
Few quick patches
nbitzz Mar 10, 2024
d0c1c7b
port /:fileId
nbitzz Mar 10, 2024
a062a98
add etags ill do ore laterr
nbitzz Mar 11, 2024
e7779b2
Finally fix /:fileId
nbitzz Mar 26, 2024
5888395
Oh shit wait
nbitzz Mar 26, 2024
0bf5f6f
Genius
nbitzz Mar 26, 2024
4add8a5
Fix 500 error which should be 404
nbitzz Mar 26, 2024
a62f1cf
/api/v1/file
nbitzz Mar 27, 2024
8d6c6a5
IPPEE
nbitzz Mar 27, 2024
dbe3059
terrifying
nbitzz Mar 27, 2024
010a2bf
AAAAAAAAAAAAAAAAAAA
nbitzz Mar 27, 2024
77cfa27
real quick; i'll port more stuff over later...
nbitzz Mar 27, 2024
f441e06
Port client to TypeScript
nbitzz Mar 28, 2024
d5cf147
Bring back /cpt
nbitzz Apr 27, 2024
2132945
start unify config, create dockerfile
cirroskais Apr 28, 2024
9fba6b1
mail.ts uses unified config
cirroskais Apr 28, 2024
c214a06
more unifying work
cirroskais Apr 28, 2024
f7f8b39
typo
cirroskais Apr 28, 2024
1da5f0e
fix crashes
nbitzz Apr 28, 2024
4264ee4
make image actually buildable
cirroskais Apr 28, 2024
e6ca2c3
make api routes mountable
cirroskais Apr 28, 2024
a25d268
add docker-compose example
cirroskais Apr 28, 2024
be5ec97
copy over assets to image
cirroskais Apr 28, 2024
fadad4b
Update .env.example
cirroskais Apr 29, 2024
144d2c6
Fuck you! You, fuckin' dick. Always nay-saying!
cirroskais Apr 29, 2024
76a7cd9
Dick
cirroskais Apr 29, 2024
ef6eb1e
Merge branch 'mollersuite:api-v1' into api-v1
cirroskais Apr 29, 2024
2112c75
Merge pull request #62 from cirroskais/api-v1
nbitzz Apr 29, 2024
5672a6e
oh wait we dont need that
nbitzz Apr 30, 2024
ff46b03
Onhfuckfuck
nbitzz Apr 30, 2024
364c362
/api/v1/info
nbitzz May 1, 2024
e4a4e24
add some stuff
nbitzz May 1, 2024
8a26ace
initial commit
nbitzz May 1, 2024
f0a2450
i think we're done actually
nbitzz May 1, 2024
5155e64
i think thats probably etter actually.
nbitzz May 1, 2024
5c3a324
Merge pull request #69 from mollersuite/proper-validation
nbitzz May 1, 2024
60b0308
definitely not done yet
nbitzz May 1, 2024
459c40b
basic suspension implementation
nbitzz May 1, 2024
3fbb481
initial commit
nbitzz May 1, 2024
17db908
i dont know what to do
nbitzz May 2, 2024
ce96537
access api
nbitzz May 22, 2024
1efb680
new scopes
nbitzz May 22, 2024
b5bf657
change that, actually
nbitzz May 22, 2024
0376840
FUCKFUCKFUCK
nbitzz May 22, 2024
8f13bf2
good enough
nbitzz May 22, 2024
9b68d7a
identity proofs
nbitzz May 23, 2024
da4c4d2
Kms
nbitzz May 23, 2024
82f3c31
um
nbitzz May 23, 2024
87c7b32
disable mail when not available
nbitzz May 23, 2024
a160ea7
let's do that
nbitzz May 23, 2024
bdb57fc
this is terrible. why did i do this
nbitzz May 24, 2024
dc53b2a
Update dbfile.ts
nbitzz May 24, 2024
9c2f732
move
nbitzz May 24, 2024
37f88d6
Merge pull request #77 from mollersuite/db-file-handler
nbitzz May 24, 2024
e93e56e
Merge remote-tracking branch 'origin/jwt' into jwt
nbitzz May 24, 2024
93b277e
automatically generate directories with new DbFile system
nbitzz May 24, 2024
c85de0e
prepare to switch
nbitzz May 24, 2024
594efc4
This builds but probably doesn't work yet
nbitzz May 24, 2024
06856ae
huhh
nbitzz May 24, 2024
2f32644
Merge branch 'api-v1' into jwt
nbitzz May 24, 2024
b130e4e
fix a few implementations
nbitzz May 25, 2024
eb981af
Merge pull request #70 from mollersuite/jwt
nbitzz May 25, 2024
ebcdd0c
correct exp claim in jwts
nbitzz May 25, 2024
04a3466
mirror /api/v1/session to /api/v1/account/me/access/:jti
nbitzz May 26, 2024
8845e9c
misc updates
nbitzz Jun 17, 2024
1703320
add run api for administrators
nbitzz Jun 17, 2024
426e057
barebones invite api
nbitzz Jun 17, 2024
3e834bf
dbfile stuff
nbitzz Jun 17, 2024
e01788d
files API
nbitzz Jun 18, 2024
735878f
fix generating token timers on startup
nbitzz Jun 18, 2024
c53a31c
allow PATCH /account/:id with application/x-www-form-urlencoded, limi…
nbitzz Jun 25, 2024
0f7ae63
forcing accounts for identity proofs for now (doesn't matter)
nbitzz Jun 25, 2024
ca99f85
fix invite signup teehee
nbitzz Jun 25, 2024
32a297d
why
nbitzz Jun 25, 2024
ae4252e
junj,bnb
nbitzz Jun 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions assets/icons/pound.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
},

"trustProxy": true,
"forceSSL": true
"forceSSL": false
}
39 changes: 3 additions & 36 deletions package-lock.json

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

25 changes: 7 additions & 18 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ import ServeError from "./lib/errors"
import Files from "./lib/files"
import * as auth from "./lib/auth"
import * as Accounts from "./lib/accounts"

import * as authRoutes from "./routes/authRoutes";
import * as fileApiRoutes from "./routes/fileApiRoutes";
import * as adminRoutes from "./routes/adminRoutes";
import * as primaryApi from "./routes/primaryApi";
import { getAccount } from "./lib/middleware";

import APIRouter from "./routes/api"

require("dotenv").config()

let pkg = require(`${process.cwd()}/package.json`)
Expand Down Expand Up @@ -46,19 +43,12 @@ app.get("/server",(req,res) => {
}))
})

app
.use("/auth",authRoutes.authRoutes)
.use("/admin",adminRoutes.adminRoutes)
.use("/files", fileApiRoutes.fileApiRoutes)
.use(primaryApi.primaryApi)
// funcs

// init data

if (!fs.existsSync(__dirname+"/../.data/")) fs.mkdirSync(__dirname+"/../.data/")



// discord

let client = new Client({intents:[
Expand All @@ -68,12 +58,11 @@ let client = new Client({intents:[

let files = new Files(client,config)

authRoutes.setFilesObj(files)
adminRoutes.setFilesObj(files)
fileApiRoutes.setFilesObj(files)
primaryApi.setFilesObj(files)

// routes (could probably make these use routers)
let apiRouter = new APIRouter(files)
apiRouter.loadAPIMethods().then(() => {
app.use(apiRouter.root)
console.log("API OK!")
})

// index, clone

Expand Down
33 changes: 16 additions & 17 deletions src/server/lib/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,22 @@ export interface Account {
* @returns A Promise which returns the new account's ID
*/

export function create(username:string,pwd:string,admin:boolean=false):Promise<string> {
return new Promise((resolve,reject) => {
let accId = crypto.randomBytes(12).toString("hex")

Accounts.push(
{
id: accId,
username: username,
password: password.hash(pwd),
files: [],
admin: admin,
defaultFileVisibility: "public"
}
)

save().then(() => resolve(accId))
})
export async function create(username:string,pwd:string,admin:boolean=false):Promise<string> {
let accId = crypto.randomBytes(12).toString("hex")

Accounts.push(
{
id: accId,
username: username,
password: password.hash(pwd),
files: [],
admin: admin,
defaultFileVisibility: "public"
}
)

await save()
return accId
}

/**
Expand Down
23 changes: 9 additions & 14 deletions src/server/lib/mail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,14 @@ transport =
* @returns Promise which resolves to the output from nodemailer.transport.sendMail
*/
export function sendMail(to: string, subject: string, content: string) {
return new Promise((resolve,reject) => {
transport.sendMail({
to,
subject,
"from": mailConfig.send.from,
"html": `<span style="font-size:x-large;font-weight:600;">monofile <span style="opacity:0.5">accounts</span></span><br><span style="opacity:0.5">Gain control of your uploads.</span><hr><br>${
content
.replace(/\<span username\>/g, `<span code><span style="color:#DDAA66;padding-right:3px;">@</span>`)
.replace(/\<span code\>/g,`<span style="font-family:monospace;padding:3px 5px 3px 5px;border-radius:8px;background-color:#1C1C1C;color:#DDDDDD;">`)
}<br><br><span style="opacity:0.5">If you do not believe that you are the intended recipient of this email, please disregard this message.</span>`
}, (err, info) => {
if (err) reject(err)
else resolve(info)
})
return transport.sendMail({
to,
subject,
"from": mailConfig.send.from,
"html": `<span style="font-size:x-large;font-weight:600;">monofile <span style="opacity:0.5">accounts</span></span><br><span style="opacity:0.5">Gain control of your uploads.</span><hr><br>${
content
.replace(/\<span username\>/g, `<span code><span style="color:#DDAA66;padding-right:3px;">@</span>`)
.replace(/\<span code\>/g,`<span style="font-family:monospace;padding:3px 5px 3px 5px;border-radius:8px;background-color:#1C1C1C;color:#DDDDDD;">`)
}<br><br><span style="opacity:0.5">If you do not believe that you are the intended recipient of this email, please disregard this message.</span>`
})
}
41 changes: 41 additions & 0 deletions src/server/lib/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,45 @@ export const requiresPermissions = function(...tokenPermissions: auth.TokenPermi
export const noAPIAccess: RequestHandler = function(req, res, next) {
if (auth.getType(auth.tokenFor(req)) == "App") ServeError(res, 403, "apps are not allowed to access this endpoint")
else next()
}

/**
@description Add a restriction to this route; the condition must be true to allow API requests.
*/

export const assertAPI = function(condition: (acc:Accounts.Account, token:string) => boolean):RequestHandler {
return function(req, res, next) {
let reqToken = auth.tokenFor(req)
if (auth.getType(reqToken) == "App" && condition(res.locals.acc, reqToken)) ServeError(res, 403, "apps are not allowed to access this endpoint")
else next()
}
}

type SchemeType = "array" | "object" | "string" | "number" | "boolean"

interface SchemeObject {
type: "object"
children: {
[key: string]: SchemeParameter
}
}

interface SchemeArray {
type: "array",
children: SchemeParameter /* All children of the array must be this type */
| SchemeParameter[] /* Array must match this pattern */
}

type SchemeParameter = SchemeType | SchemeObject | SchemeArray

/**
* @description Blocks requests based on whether or not the token being used to access the route is of type `User` unless a condition is met.
* @param tokenPermissions Permissions which your route requires.
* @returns Express middleware
*/

export const sanitize = function(scheme: SchemeObject):RequestHandler {
return function(req, res, next) {

}
}
Loading