-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
136 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { tableNames } from "@/v2/db/drizzle" | ||
import { relations } from "drizzle-orm" | ||
import { | ||
sqliteTable, | ||
text, | ||
// uniqueIndex, | ||
index, | ||
} from "drizzle-orm/sqlite-core" | ||
import { createInsertSchema, createSelectSchema } from "drizzle-zod" | ||
import { generateID } from "@/v2/lib/oslo" | ||
import { authUser } from "../user/user" | ||
|
||
type requestArea = "asset" | "game" | "site" | ||
|
||
export const requestForm = sqliteTable( | ||
tableNames.requestForm, | ||
{ | ||
id: text("id") | ||
.unique() | ||
.notNull() | ||
.$defaultFn(() => { | ||
return generateID() | ||
}), | ||
userId: text("user_id") | ||
.notNull() | ||
.references(() => authUser.id, { | ||
onUpdate: "cascade", | ||
onDelete: "cascade", | ||
}), | ||
area: text("type").notNull().$type<requestArea>(), | ||
title: text("title").notNull(), | ||
description: text("description").notNull(), | ||
}, | ||
(requestForm) => { | ||
return { | ||
requestFormUserIdx: index("request_form_user_id_idx").on( | ||
requestForm.userId | ||
), | ||
} | ||
} | ||
) | ||
|
||
export type RequestForm = typeof requestForm.$inferSelect | ||
export type NewRequestForm = typeof requestForm.$inferInsert | ||
export const insertRequestFormSchema = createInsertSchema(requestForm) | ||
export const selectRequestFormSchema = createSelectSchema(requestForm) | ||
|
||
export const requestFormRelations = relations(requestForm, ({ one, many }) => ({ | ||
user: one(authUser, { | ||
fields: [requestForm.userId], | ||
references: [authUser.id], | ||
relationName: "request_form_user", | ||
}), | ||
upvotes: many(requestFormUpvotes), | ||
})) | ||
|
||
export const requestFormUpvotes = sqliteTable( | ||
tableNames.requestFormUpvotes, | ||
{ | ||
id: text("id") | ||
.unique() | ||
.notNull() | ||
.$defaultFn(() => { | ||
return generateID() | ||
}), | ||
requestFormId: text("request_form_id") | ||
.notNull() | ||
.references(() => requestForm.id, { | ||
onUpdate: "cascade", | ||
onDelete: "cascade", | ||
}), | ||
userId: text("user_id") | ||
.notNull() | ||
.references(() => authUser.id, { | ||
onUpdate: "cascade", | ||
onDelete: "cascade", | ||
}), | ||
}, | ||
(requestFormUpvotes) => { | ||
return { | ||
requestFormUpvotesIdx: index("request_form_upvotes_idx").on( | ||
requestFormUpvotes.requestFormId, | ||
requestFormUpvotes.userId | ||
), | ||
} | ||
} | ||
) | ||
|
||
export type RequestFormUpvotes = typeof requestFormUpvotes.$inferSelect | ||
export type NewRequestFormUpvotes = typeof requestFormUpvotes.$inferInsert | ||
export const insertRequestFormUpvotesSchema = | ||
createInsertSchema(requestFormUpvotes) | ||
export const selectRequestFormUpvotesSchema = | ||
createSelectSchema(requestFormUpvotes) | ||
|
||
export const requestFormUpvotesRelations = relations( | ||
requestFormUpvotes, | ||
({ one }) => ({ | ||
user: one(authUser, { | ||
fields: [requestFormUpvotes.userId], | ||
references: [authUser.id], | ||
relationName: "request_form_upvotes_user", | ||
}), | ||
requestForm: one(requestForm, { | ||
fields: [requestFormUpvotes.requestFormId], | ||
references: [requestForm.id], | ||
relationName: "request_form_upvotes_request_form", | ||
}), | ||
}) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import dayjs from "dayjs" | ||
import { Context, MiddlewareHandler } from "hono" | ||
|
||
const fakeDomain = "http://rate-limiter.com/" | ||
const fakeDomain = "http://fake.wanderer.moe/" | ||
|
||
const getRateLimitKey = (ctx: Context) => { | ||
const ip = ctx.req.header("cf-connecting-ip") | ||
|
@@ -92,7 +92,7 @@ export const rateLimit = ( | |
{ | ||
success: false, | ||
message: | ||
"Rate limit exceeded, contact [email protected] if you're using this API in production and need a higher rate limit.", | ||
"Rate limit exceeded, contact [email protected] or reach out to @dromzeh on discord if you're using this API in production and need a higher rate limit.", | ||
}, | ||
429 | ||
) | ||
|