Compare commits
1 Commits
main
...
a6200605f8
| Author | SHA1 | Date | |
|---|---|---|---|
| a6200605f8 |
@ -28,7 +28,6 @@ Table medias {
|
||||
deletedAt DateTime
|
||||
createdAt DateTime [default: `now()`, not null]
|
||||
updatedAt DateTime [default: `now()`, not null]
|
||||
bannerPromotion hero_banner [not null]
|
||||
logs media_logs [not null]
|
||||
episodes episodes [not null]
|
||||
collections collections [not null]
|
||||
@ -497,8 +496,12 @@ Table email_system_histories {
|
||||
Table hero_banner {
|
||||
id String [pk]
|
||||
orderPriority Int [unique]
|
||||
mediaId String [not null]
|
||||
media medias [not null]
|
||||
isClickable Boolean [not null, default: false]
|
||||
title String
|
||||
tags String[] [not null]
|
||||
description String
|
||||
buttonContent String
|
||||
buttonLink String
|
||||
imageUrl String
|
||||
startDate DateTime [not null]
|
||||
endDate DateTime [not null]
|
||||
@ -777,8 +780,6 @@ Ref: email_system_accounts.createdBy > users.id
|
||||
|
||||
Ref: email_system_histories.userRelated > users.id
|
||||
|
||||
Ref: hero_banner.mediaId > medias.id
|
||||
|
||||
Ref: hero_banner.creatorId > users.id
|
||||
|
||||
Ref: system_notifications.createdBy > users.id
|
||||
|
||||
@ -206,8 +206,7 @@ CREATE TABLE "videos" (
|
||||
"id" UUID NOT NULL,
|
||||
"episodeId" UUID NOT NULL,
|
||||
"serviceId" UUID NOT NULL,
|
||||
"videoCode" VARCHAR(255) NOT NULL,
|
||||
"thumbnailCode" TEXT,
|
||||
"code" VARCHAR(255) NOT NULL,
|
||||
"pendingUpload" BOOLEAN NOT NULL DEFAULT true,
|
||||
"uploadedBy" UUID NOT NULL,
|
||||
"deletedAt" TIMESTAMP(3),
|
||||
@ -498,26 +497,6 @@ CREATE TABLE "email_system_histories" (
|
||||
CONSTRAINT "email_system_histories_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "hero_banner" (
|
||||
"id" UUID NOT NULL,
|
||||
"orderPriority" INTEGER,
|
||||
"isClickable" BOOLEAN NOT NULL DEFAULT false,
|
||||
"title" VARCHAR(225),
|
||||
"tags" TEXT[],
|
||||
"description" TEXT,
|
||||
"buttonContent" VARCHAR(100),
|
||||
"buttonLink" TEXT,
|
||||
"imageUrl" TEXT,
|
||||
"startDate" TIMESTAMP(3) NOT NULL,
|
||||
"endDate" TIMESTAMP(3) NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"creatorId" UUID NOT NULL,
|
||||
|
||||
CONSTRAINT "hero_banner_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "system_preferences" (
|
||||
"id" UUID NOT NULL,
|
||||
@ -650,7 +629,7 @@ CREATE UNIQUE INDEX "lang_va_char_language_vaId_charId_key" ON "lang_va_char"("l
|
||||
CREATE UNIQUE INDEX "episodes_mediaId_episode_key" ON "episodes"("mediaId", "episode");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "videos_serviceId_videoCode_key" ON "videos"("serviceId", "videoCode");
|
||||
CREATE UNIQUE INDEX "videos_serviceId_code_key" ON "videos"("serviceId", "code");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "video_services_name_key" ON "video_services"("name");
|
||||
@ -685,12 +664,6 @@ CREATE UNIQUE INDEX "email_system_accounts_email_key" ON "email_system_accounts"
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "email_system_accounts_username_key" ON "email_system_accounts"("username");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "hero_banner_orderPriority_key" ON "hero_banner"("orderPriority");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "system_preferences_key_key" ON "system_preferences"("key");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "_MediaStudios_B_index" ON "_MediaStudios"("B");
|
||||
|
||||
@ -847,9 +820,6 @@ ALTER TABLE "email_system_accounts" ADD CONSTRAINT "email_system_accounts_create
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "email_system_histories" ADD CONSTRAINT "email_system_histories_userRelated_fkey" FOREIGN KEY ("userRelated") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "hero_banner" ADD CONSTRAINT "hero_banner_creatorId_fkey" FOREIGN KEY ("creatorId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "system_notifications" ADD CONSTRAINT "system_notifications_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `code` on the `videos` table. All the data in the column will be lost.
|
||||
- A unique constraint covering the columns `[serviceId,videoCode]` on the table `videos` will be added. If there are existing duplicate values, this will fail.
|
||||
- Added the required column `videoCode` to the `videos` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- DropIndex
|
||||
DROP INDEX "videos_serviceId_code_key";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "videos" RENAME COLUMN "code" TO "videoCode";
|
||||
|
||||
-- CreateIndex
|
||||
DROP INDEX IF EXISTS "videos_serviceId_code_key";
|
||||
CREATE UNIQUE INDEX "videos_serviceId_videoCode_key" ON "videos"("serviceId", "videoCode");
|
||||
@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "videos" ADD COLUMN "thumbnailCode" TEXT;
|
||||
@ -0,0 +1,20 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "HeroBanner" (
|
||||
"id" UUID NOT NULL,
|
||||
"isClickable" BOOLEAN NOT NULL DEFAULT false,
|
||||
"title" VARCHAR(225),
|
||||
"description" TEXT,
|
||||
"buttonContent" VARCHAR(100),
|
||||
"buttonLink" TEXT,
|
||||
"imageUrl" TEXT,
|
||||
"startDate" TIMESTAMP(3) NOT NULL,
|
||||
"endDate" TIMESTAMP(3) NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"creatorId" UUID NOT NULL,
|
||||
|
||||
CONSTRAINT "HeroBanner_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "HeroBanner" ADD CONSTRAINT "HeroBanner_creatorId_fkey" FOREIGN KEY ("creatorId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
@ -0,0 +1,32 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the `HeroBanner` table. If the table is not empty, all the data it contains will be lost.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "HeroBanner" DROP CONSTRAINT "HeroBanner_creatorId_fkey";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "HeroBanner";
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "hero_banner" (
|
||||
"id" UUID NOT NULL,
|
||||
"isClickable" BOOLEAN NOT NULL DEFAULT false,
|
||||
"title" VARCHAR(225),
|
||||
"description" TEXT,
|
||||
"buttonContent" VARCHAR(100),
|
||||
"buttonLink" TEXT,
|
||||
"imageUrl" TEXT,
|
||||
"startDate" TIMESTAMP(3) NOT NULL,
|
||||
"endDate" TIMESTAMP(3) NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"creatorId" UUID NOT NULL,
|
||||
|
||||
CONSTRAINT "hero_banner_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "hero_banner" ADD CONSTRAINT "hero_banner_creatorId_fkey" FOREIGN KEY ("creatorId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
@ -0,0 +1,11 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- A unique constraint covering the columns `[order]` on the table `hero_banner` will be added. If there are existing duplicate values, this will fail.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "hero_banner" ADD COLUMN "order" INTEGER;
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "hero_banner_order_key" ON "hero_banner"("order");
|
||||
@ -0,0 +1,16 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `order` on the `hero_banner` table. All the data in the column will be lost.
|
||||
- A unique constraint covering the columns `[orderPriority]` on the table `hero_banner` will be added. If there are existing duplicate values, this will fail.
|
||||
|
||||
*/
|
||||
-- DropIndex
|
||||
DROP INDEX "hero_banner_order_key";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "hero_banner" DROP COLUMN "order",
|
||||
ADD COLUMN "orderPriority" INTEGER;
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "hero_banner_orderPriority_key" ON "hero_banner"("orderPriority");
|
||||
@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "hero_banner" ADD COLUMN "tags" TEXT[];
|
||||
@ -0,0 +1,8 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- A unique constraint covering the columns `[key]` on the table `system_preferences` will be added. If there are existing duplicate values, this will fail.
|
||||
|
||||
*/
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "system_preferences_key_key" ON "system_preferences"("key");
|
||||
@ -1,23 +0,0 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `buttonContent` on the `hero_banner` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `buttonLink` on the `hero_banner` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `description` on the `hero_banner` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `isClickable` on the `hero_banner` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `tags` on the `hero_banner` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `title` on the `hero_banner` table. All the data in the column will be lost.
|
||||
- Added the required column `mediaId` to the `hero_banner` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "hero_banner" DROP COLUMN "buttonContent",
|
||||
DROP COLUMN "buttonLink",
|
||||
DROP COLUMN "description",
|
||||
DROP COLUMN "isClickable",
|
||||
DROP COLUMN "tags",
|
||||
DROP COLUMN "title",
|
||||
ADD COLUMN "mediaId" UUID NOT NULL;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "hero_banner" ADD CONSTRAINT "hero_banner_mediaId_fkey" FOREIGN KEY ("mediaId") REFERENCES "medias"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
@ -49,7 +49,6 @@ model Media {
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
|
||||
bannerPromotion HeroBanner[] @relation("MediaBannerPromotion")
|
||||
logs MediaLog[] @relation("MediaLogs")
|
||||
episodes Episode[] @relation("MediaEpisodes")
|
||||
collections Collection[] @relation("MediaCollections")
|
||||
@ -558,8 +557,12 @@ model EmailSystemHistory {
|
||||
model HeroBanner {
|
||||
id String @id @db.Uuid
|
||||
orderPriority Int? @unique
|
||||
mediaId String @db.Uuid
|
||||
media Media @relation("MediaBannerPromotion", fields: [mediaId], references: [id])
|
||||
isClickable Boolean @default(false)
|
||||
title String? @db.VarChar(225)
|
||||
tags String[]
|
||||
description String? @db.Text
|
||||
buttonContent String? @db.VarChar(100)
|
||||
buttonLink String? @db.Text
|
||||
imageUrl String? @db.Text
|
||||
startDate DateTime
|
||||
endDate DateTime
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { Context } from "elysia";
|
||||
import { UserHeaderInformation } from "./types";
|
||||
|
||||
export interface ClientInfoHeader {
|
||||
@ -9,14 +10,25 @@ export interface ClientInfoHeader {
|
||||
ip: string;
|
||||
}
|
||||
|
||||
export const getUserHeaderInformation = (clientInfo: string): UserHeaderInformation => {
|
||||
const clientInfoHeader = (JSON.parse(clientInfo) as ClientInfoHeader) ?? ("unknown" as string);
|
||||
export const getUserHeaderInformation = (
|
||||
ctx: Context,
|
||||
): UserHeaderInformation => {
|
||||
const clientInfoHeader =
|
||||
(JSON.parse(
|
||||
ctx.request.headers.get("x-client-info") as string,
|
||||
) as ClientInfoHeader) ?? ("unknown" as string);
|
||||
|
||||
const userHeaderInformation = {
|
||||
ip: clientInfoHeader.ip ?? "unknown",
|
||||
deviceType: clientInfoHeader.deviceType ?? "unknown",
|
||||
deviceOS: (clientInfoHeader.os ?? "unknown") + " " + (clientInfoHeader.osVersion ?? "unknown"),
|
||||
browser: (clientInfoHeader.browser ?? "unknown") + " " + (clientInfoHeader.browserVersion ?? "unknown"),
|
||||
deviceOS:
|
||||
(clientInfoHeader.os ?? "unknown") +
|
||||
" " +
|
||||
(clientInfoHeader.osVersion ?? "unknown"),
|
||||
browser:
|
||||
(clientInfoHeader.browser ?? "unknown") +
|
||||
" " +
|
||||
(clientInfoHeader.browserVersion ?? "unknown"),
|
||||
};
|
||||
|
||||
return userHeaderInformation;
|
||||
|
||||
@ -1,17 +1,14 @@
|
||||
import { Context, Static } from "elysia";
|
||||
import { Context } from "elysia";
|
||||
import { returnWriteResponse } from "../../../helpers/callback/httpResponse";
|
||||
import { githubCallbackService } from "../services/http/githubCallback.service";
|
||||
import { mainErrorHandler } from "../../../helpers/error/handler";
|
||||
import { getUserHeaderInformation } from "../../../helpers/http/userHeader/getUserHeaderInformation";
|
||||
import { githubCallbackSchema } from "../schemas/githubCallback.schema";
|
||||
|
||||
export const githubCallbackController = async (ctx: {
|
||||
set: Context["set"];
|
||||
query: Static<typeof githubCallbackSchema.query>;
|
||||
headers: Static<typeof githubCallbackSchema.headers>;
|
||||
}) => {
|
||||
export const githubCallbackController = async (
|
||||
ctx: Context & { query: { code: string; callbackURI: string } }
|
||||
) => {
|
||||
try {
|
||||
const userHeaderInfo = getUserHeaderInformation(ctx.headers["x-client-info"]);
|
||||
const userHeaderInfo = getUserHeaderInformation(ctx);
|
||||
|
||||
const authToken = await githubCallbackService(ctx.query, userHeaderInfo);
|
||||
return returnWriteResponse(ctx.set, 200, "Authenticated successfully!", {
|
||||
|
||||
@ -1,18 +1,21 @@
|
||||
import { Context, Static } from "elysia";
|
||||
import { Context } from "elysia";
|
||||
import { returnReadResponse } from "../../../helpers/callback/httpResponse";
|
||||
import { githubRequestService } from "../services/http/githubRequest.service";
|
||||
import { mainErrorHandler } from "../../../helpers/error/handler";
|
||||
import { githubRequestSchema } from "../schemas/githubRequest.schema";
|
||||
|
||||
export const githubRequestController = async (ctx: {
|
||||
set: Context["set"];
|
||||
query: Static<typeof githubRequestSchema.query>;
|
||||
}) => {
|
||||
export const githubRequestController = async (
|
||||
ctx: Context & { query: { callback?: string } },
|
||||
) => {
|
||||
try {
|
||||
const loginUrl = await githubRequestService(ctx.query.callback);
|
||||
return returnReadResponse(ctx.set, 200, "GitHub login URL created successfully.", {
|
||||
endpointUrl: loginUrl,
|
||||
});
|
||||
return returnReadResponse(
|
||||
ctx.set,
|
||||
200,
|
||||
"Login URL generated successfully",
|
||||
{
|
||||
endpointUrl: loginUrl,
|
||||
},
|
||||
);
|
||||
} catch (error) {
|
||||
return mainErrorHandler(ctx.set, error);
|
||||
}
|
||||
|
||||
@ -1,20 +1,17 @@
|
||||
import { Context, Static } from "elysia";
|
||||
import { Context } from "elysia";
|
||||
import { returnReadResponse } from "../../../helpers/callback/httpResponse";
|
||||
import { mainErrorHandler } from "../../../helpers/error/handler";
|
||||
import { googleCallbackService } from "../services/http/googleCallback.service";
|
||||
import { getUserHeaderInformation } from "../../../helpers/http/userHeader/getUserHeaderInformation";
|
||||
import { googleCallbackSchema } from "../schemas/googleCallback.schema";
|
||||
|
||||
export const googleCallbackController = async (ctx: {
|
||||
set: Context["set"];
|
||||
query: Static<typeof googleCallbackSchema.query>;
|
||||
headers: Static<typeof googleCallbackSchema.headers>;
|
||||
}) => {
|
||||
export const googleCallbackController = async (
|
||||
ctx: Context & { query: { code: string; state: string; callbackURI: string } }
|
||||
) => {
|
||||
try {
|
||||
const userHeaderInfo = getUserHeaderInformation(ctx.headers["x-client-info"]);
|
||||
const userHeaderInfo = getUserHeaderInformation(ctx);
|
||||
|
||||
const authToken = await googleCallbackService(ctx.query, userHeaderInfo);
|
||||
return returnReadResponse(ctx.set, 200, "Authentication successful!", {
|
||||
return returnReadResponse(ctx.set, 200, "Authenticated successfully!", {
|
||||
authToken,
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
@ -1,16 +1,14 @@
|
||||
import { Context, Static } from "elysia";
|
||||
import { Context } from "elysia";
|
||||
import { mainErrorHandler } from "../../../helpers/error/handler";
|
||||
import { googleRequestService } from "../services/http/googleRequest.service";
|
||||
import { returnReadResponse } from "../../../helpers/callback/httpResponse";
|
||||
import { googleRequestSchema } from "../schemas/googleRequest.schema";
|
||||
|
||||
export const googleRequestController = async (ctx: {
|
||||
set: Context["set"];
|
||||
query: Static<typeof googleRequestSchema.query>;
|
||||
}) => {
|
||||
export const googleRequestController = async (
|
||||
ctx: Context & { query: { callback?: string } }
|
||||
) => {
|
||||
try {
|
||||
const loginUrl = await googleRequestService(ctx.query.callback);
|
||||
return returnReadResponse(ctx.set, 200, "Google login URL created successfully.", {
|
||||
return returnReadResponse(ctx.set, 200, "Google login url created!", {
|
||||
endpointUrl: loginUrl,
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
@ -9,19 +9,13 @@ import { tokenValidationController } from "./controllers/tokenValidation.control
|
||||
import { logoutController } from "./controllers/logout.controller";
|
||||
import { tokenValidationSchema } from "./schemas/tokenValidation.schema";
|
||||
import { getOauthProvidersSchema } from "./schemas/getOauthProviders.schema";
|
||||
import { getCallbackProviderUrlSchema } from "./schemas/getCallbackProviderUrl.schema";
|
||||
import { googleRequestSchema } from "./schemas/googleRequest.schema";
|
||||
import { googleCallbackSchema } from "./schemas/googleCallback.schema";
|
||||
import { githubRequestSchema } from "./schemas/githubRequest.schema";
|
||||
import { githubCallbackSchema } from "./schemas/githubCallback.schema";
|
||||
import { logoutSchema } from "./schemas/logout.schema";
|
||||
|
||||
export const authModule = new Elysia({ prefix: "/auth", tags: ["Authentication"] })
|
||||
.post("/token/validate", tokenValidationController, tokenValidationSchema)
|
||||
.get("/providers", getOauthProvidersController, getOauthProvidersSchema)
|
||||
.get("/providers/:name/callback", getCallbackProviderUrlController, getCallbackProviderUrlSchema)
|
||||
.get("/google", googleRequestController, googleRequestSchema)
|
||||
.get("/google/callback", googleCallbackController, googleCallbackSchema)
|
||||
.get("/github", githubRequestController, githubRequestSchema)
|
||||
.get("/github/callback", githubCallbackController, githubCallbackSchema)
|
||||
.post("/logout", logoutController, logoutSchema);
|
||||
.get("/providers/:name/callback", getCallbackProviderUrlController)
|
||||
.get("/github", githubRequestController)
|
||||
.get("/github/callback", githubCallbackController)
|
||||
.get("/google", googleRequestController)
|
||||
.get("/google/callback", googleCallbackController)
|
||||
.post("/logout", logoutController);
|
||||
|
||||
@ -1,45 +0,0 @@
|
||||
import { AppRouteSchema } from "../../../helpers/types/AppRouteSchema";
|
||||
|
||||
export const getCallbackProviderUrlSchema = {
|
||||
detail: {
|
||||
summary: "Get the callback URL of oauth provider",
|
||||
description:
|
||||
"After users have successfully completed the authentication process on the OAuth provider page, they will be redirected to the callback page on the frontend. This endpoint aims to obtain the actual endpoint for each OAuth response handler.",
|
||||
responses: {
|
||||
200: {
|
||||
description: "The callback URL on the provider has been found.",
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
success: {
|
||||
type: "boolean",
|
||||
default: true,
|
||||
},
|
||||
status: {
|
||||
type: "number",
|
||||
default: 200,
|
||||
},
|
||||
message: {
|
||||
type: "string",
|
||||
default: "The callback URL on the provider has been found.",
|
||||
},
|
||||
data: {
|
||||
type: "object",
|
||||
properties: {
|
||||
callback_url: {
|
||||
type: "string",
|
||||
description: "The callback URL on the provider.",
|
||||
example: "auth/google/callback",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} satisfies AppRouteSchema;
|
||||
@ -1,3 +1,4 @@
|
||||
import { success } from "zod";
|
||||
import { AppRouteSchema } from "../../../helpers/types/AppRouteSchema";
|
||||
|
||||
export const getOauthProvidersSchema = {
|
||||
|
||||
@ -1,57 +0,0 @@
|
||||
import { t } from "elysia";
|
||||
import { AppRouteSchema } from "../../../helpers/types/AppRouteSchema";
|
||||
|
||||
export const githubCallbackSchema = {
|
||||
headers: t.Object({
|
||||
"x-client-info": t.String({
|
||||
examples: [
|
||||
'{"os":"Windows","osVersion":"10","browser":"Chrome","browserVersion":"89.0.4389.82","deviceType":"Desktop","ip":"192.168.1.1"}',
|
||||
],
|
||||
}),
|
||||
}),
|
||||
query: t.Object({
|
||||
code: t.String({ examples: ["4/0AY0e-xxxxxxxxx"] }),
|
||||
callbackURI: t.String({ examples: ["https://example.com/auth/github/callback"] }),
|
||||
}),
|
||||
detail: {
|
||||
summary: "GitHub OAuth callback endpoint",
|
||||
description:
|
||||
"Handles the callback from GitHub OAuth and processes the authentication response. This endpoint also processes the account provisioning if the user is logging in for the first time.",
|
||||
responses: {
|
||||
200: {
|
||||
description: "Authentication successful",
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
success: {
|
||||
type: "boolean",
|
||||
example: true,
|
||||
},
|
||||
status: {
|
||||
type: "number",
|
||||
example: 200,
|
||||
},
|
||||
message: {
|
||||
type: "string",
|
||||
example: "Authentication successful",
|
||||
},
|
||||
data: {
|
||||
type: "object",
|
||||
properties: {
|
||||
authToken: {
|
||||
type: "string",
|
||||
description: "JWT token for authenticated user",
|
||||
example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} satisfies AppRouteSchema;
|
||||
@ -1,54 +0,0 @@
|
||||
import { t } from "elysia";
|
||||
import { AppRouteSchema } from "../../../helpers/types/AppRouteSchema";
|
||||
|
||||
export const githubRequestSchema = {
|
||||
query: t.Object({
|
||||
callback: t.Optional(
|
||||
t.String({
|
||||
description: "The callback URL to redirect after GitHub authentication. It should be URL-encoded if provided.",
|
||||
}),
|
||||
),
|
||||
}),
|
||||
detail: {
|
||||
summary: "Initiate GitHub OAuth flow",
|
||||
description:
|
||||
"This endpoint initiates the GitHub OAuth flow by redirecting the user to GitHub's authentication page.",
|
||||
responses: {
|
||||
200: {
|
||||
description: "GitHub login URL created successfully.",
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
success: {
|
||||
type: "boolean",
|
||||
default: true,
|
||||
},
|
||||
status: {
|
||||
type: "number",
|
||||
default: 200,
|
||||
},
|
||||
message: {
|
||||
type: "string",
|
||||
default: "GitHub login URL created successfully.",
|
||||
},
|
||||
data: {
|
||||
type: "object",
|
||||
properties: {
|
||||
endpointUrl: {
|
||||
type: "string",
|
||||
description: "The URL to redirect the user for GitHub authentication.",
|
||||
example:
|
||||
"https://github.com/login/oauth/authorize?client_id=YOUR_CLIENT_ID&redirect_uri=YOUR_REDIRECT_URI&response_type=code&scope=user:email",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} satisfies AppRouteSchema;
|
||||
@ -1,58 +0,0 @@
|
||||
import { t } from "elysia";
|
||||
import { AppRouteSchema } from "../../../helpers/types/AppRouteSchema";
|
||||
|
||||
export const googleCallbackSchema = {
|
||||
headers: t.Object({
|
||||
"x-client-info": t.String({
|
||||
examples: [
|
||||
'{"os":"Windows","osVersion":"10","browser":"Chrome","browserVersion":"89.0.4389.82","deviceType":"Desktop","ip":"192.168.1.1"}',
|
||||
],
|
||||
}),
|
||||
}),
|
||||
query: t.Object({
|
||||
code: t.String({ examples: ["4/0AY0e-xxxxxxxxx"] }),
|
||||
state: t.String({ examples: ["random_state_string"] }),
|
||||
callbackURI: t.String({ examples: ["https://example.com/auth/google/callback"] }),
|
||||
}),
|
||||
detail: {
|
||||
summary: "Google OAuth callback endpoint",
|
||||
description:
|
||||
"Handles the callback from Google OAuth and processes the authentication response. This endpoint also processes the account provisioning if the user is logging in for the first time.",
|
||||
responses: {
|
||||
200: {
|
||||
description: "Authentication successful",
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
success: {
|
||||
type: "boolean",
|
||||
example: true,
|
||||
},
|
||||
status: {
|
||||
type: "number",
|
||||
example: 200,
|
||||
},
|
||||
message: {
|
||||
type: "string",
|
||||
example: "Authentication successful",
|
||||
},
|
||||
data: {
|
||||
type: "object",
|
||||
properties: {
|
||||
authToken: {
|
||||
type: "string",
|
||||
description: "JWT token for authenticated user",
|
||||
example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} satisfies AppRouteSchema;
|
||||
@ -1,54 +0,0 @@
|
||||
import { t } from "elysia";
|
||||
import { AppRouteSchema } from "../../../helpers/types/AppRouteSchema";
|
||||
|
||||
export const googleRequestSchema = {
|
||||
query: t.Object({
|
||||
callback: t.Optional(
|
||||
t.String({
|
||||
description: "The callback URL to redirect after Google authentication. It should be URL-encoded if provided.",
|
||||
}),
|
||||
),
|
||||
}),
|
||||
detail: {
|
||||
summary: "Initiate Google OAuth flow",
|
||||
description:
|
||||
"This endpoint initiates the Google OAuth flow by redirecting the user to Google's authentication page.",
|
||||
responses: {
|
||||
200: {
|
||||
description: "Google login URL created successfully.",
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
success: {
|
||||
type: "boolean",
|
||||
default: true,
|
||||
},
|
||||
status: {
|
||||
type: "number",
|
||||
default: 200,
|
||||
},
|
||||
message: {
|
||||
type: "string",
|
||||
default: "Google login URL created successfully.",
|
||||
},
|
||||
data: {
|
||||
type: "object",
|
||||
properties: {
|
||||
endpointUrl: {
|
||||
type: "string",
|
||||
description: "The URL to redirect the user for Google authentication.",
|
||||
example:
|
||||
"https://accounts.google.com/o/oauth2/v2/auth?client_id=YOUR_CLIENT_ID&redirect_uri=YOUR_REDIRECT_URI&response_type=code&scope=email%20profile",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} satisfies AppRouteSchema;
|
||||
@ -1,97 +0,0 @@
|
||||
import { AppRouteSchema } from "../../../helpers/types/AppRouteSchema";
|
||||
|
||||
export const logoutSchema = {
|
||||
detail: {
|
||||
summary: "Logout endpoint",
|
||||
description: "Logs out the authenticated user by invalidating their session or token.",
|
||||
responses: {
|
||||
200: {
|
||||
description: "Logout successful",
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
success: {
|
||||
type: "boolean",
|
||||
example: true,
|
||||
},
|
||||
status: {
|
||||
type: "number",
|
||||
example: 200,
|
||||
},
|
||||
message: {
|
||||
type: "string",
|
||||
example: "Logout successful",
|
||||
},
|
||||
data: {
|
||||
type: "object",
|
||||
description: "Details about the logout operation. This only returned in development environment.",
|
||||
properties: {
|
||||
id: {
|
||||
type: "string",
|
||||
example: "123e4567-e89b-12d3-a456-426614174000",
|
||||
},
|
||||
isAuthenticated: {
|
||||
type: "boolean",
|
||||
example: false,
|
||||
},
|
||||
validUntil: {
|
||||
type: "string",
|
||||
format: "date-time",
|
||||
example: "2024-12-31T23:59:59Z",
|
||||
},
|
||||
userId: {
|
||||
type: "string",
|
||||
example: "user_12345",
|
||||
},
|
||||
deletedAt: {
|
||||
type: "string",
|
||||
format: "date-time",
|
||||
example: "2024-01-02T12:00:00Z",
|
||||
},
|
||||
createdAt: {
|
||||
type: "string",
|
||||
format: "date-time",
|
||||
example: "2024-01-01T12:00:00Z",
|
||||
},
|
||||
updatedAt: {
|
||||
type: "string",
|
||||
format: "date-time",
|
||||
example: "2024-01-02T12:00:00Z",
|
||||
},
|
||||
deviceType: {
|
||||
type: "string",
|
||||
example: "Desktop",
|
||||
},
|
||||
deviceOs: {
|
||||
type: "string",
|
||||
example: "Windows 10",
|
||||
},
|
||||
deviceIp: {
|
||||
type: "string",
|
||||
example: "192.168.1.1",
|
||||
},
|
||||
browser: {
|
||||
type: "string",
|
||||
example: "Chrome 89.0.4389.82",
|
||||
},
|
||||
isOnline: {
|
||||
type: "boolean",
|
||||
example: false,
|
||||
},
|
||||
lastOnline: {
|
||||
type: "string",
|
||||
format: "date-time",
|
||||
example: "2024-01-02T12:00:00Z",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} satisfies AppRouteSchema;
|
||||
@ -1,8 +0,0 @@
|
||||
import { Context } from "elysia";
|
||||
import { returnWriteResponse } from "../../../helpers/callback/httpResponse";
|
||||
import { clearHeroBannerService } from "../services/clearHeroBanner.service";
|
||||
|
||||
export const clearHeroBannerController = async (ctx: { set: Context["set"] }) => {
|
||||
const cacheCleared = await clearHeroBannerService();
|
||||
return returnWriteResponse(ctx.set, 200, "Hero banner cache flushed successfully", cacheCleared);
|
||||
};
|
||||
@ -1,4 +0,0 @@
|
||||
import Elysia from "elysia";
|
||||
import { clearHeroBannerController } from "./controllers/clearHeroBanner.controller";
|
||||
|
||||
export const flushCacheModule = new Elysia({ prefix: "/flush-cache" }).put("/hero-banner", clearHeroBannerController);
|
||||
@ -1,12 +0,0 @@
|
||||
import { redisKey } from "../../../config/redis/key";
|
||||
import { AppError } from "../../../helpers/error/instances/app";
|
||||
import { redis } from "../../../utils/databases/redis/connection";
|
||||
|
||||
export const clearHeroBannerService = async () => {
|
||||
try {
|
||||
const cache = await redis.del(redisKey.find((key) => key.name === "HERO_BANNER")?.key || "");
|
||||
return cache > 0; // Returns true if cache was cleared, false if it was not found
|
||||
} catch (error) {
|
||||
throw new AppError(500, "Failed to clear hero banner cache", error);
|
||||
}
|
||||
};
|
||||
@ -20,25 +20,6 @@ export const findAllActiveHeroBannerRepository = async () => {
|
||||
startDate: "asc",
|
||||
},
|
||||
],
|
||||
select: {
|
||||
orderPriority: true,
|
||||
imageUrl: true,
|
||||
media: {
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
slug: true,
|
||||
pictureLarge: true,
|
||||
synopsis: true,
|
||||
genres: {
|
||||
select: {
|
||||
slug: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
throw new AppError(500, "Failed to fetch active hero banners", error);
|
||||
|
||||
@ -8,31 +8,26 @@ import { findAllActiveHeroBannerRepository } from "../repositories/GET/findAllAc
|
||||
export const getActiveHeroBannerService = async () => {
|
||||
try {
|
||||
// Check if Hero Banner is enabled in system preferences
|
||||
const isHeroBannerEnabled = await findSystemPreferenceService("HERO_BANNER_ENABLED", "boolean");
|
||||
if (!isHeroBannerEnabled) throw new AppError(403, "Hero Banner is disabled");
|
||||
const isHeroBannerEnabled = await findSystemPreferenceService(
|
||||
"HERO_BANNER_ENABLED",
|
||||
"boolean",
|
||||
);
|
||||
if (!isHeroBannerEnabled)
|
||||
throw new AppError(403, "Hero Banner is disabled");
|
||||
|
||||
// Try to get active banners from Redis cache
|
||||
const cachedBanners = await redis.get(`${redisKey.filter((key) => key.name === "HERO_BANNER")[0].key}`);
|
||||
const cachedBanners = await redis.get(
|
||||
`${redisKey.filter((key) => key.name === "HERO_BANNER")[0].key}`,
|
||||
);
|
||||
if (cachedBanners) return JSON.parse(cachedBanners);
|
||||
|
||||
// If not in cache, fetch from database and cache the result
|
||||
const activeBanners = await findAllActiveHeroBannerRepository();
|
||||
const constructedBanners = activeBanners.map((banner) => ({
|
||||
id: banner.media.id,
|
||||
title: banner.media.title,
|
||||
slug: banner.media.slug,
|
||||
imageUrl: banner.imageUrl || banner.media.pictureLarge,
|
||||
synopsis: banner.media.synopsis,
|
||||
genres: banner.media.genres.map((genre) => ({
|
||||
slug: genre.slug,
|
||||
name: genre.name,
|
||||
})),
|
||||
}));
|
||||
await redis.set(
|
||||
`${redisKey.filter((key) => key.name === "HERO_BANNER")[0].key}`,
|
||||
JSON.stringify(constructedBanners),
|
||||
JSON.stringify(activeBanners),
|
||||
);
|
||||
return constructedBanners;
|
||||
return activeBanners;
|
||||
} catch (error) {
|
||||
ErrorForwarder(error);
|
||||
}
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { AppError } from "../../../helpers/error/instances/app";
|
||||
import { prisma } from "../../../utils/databases/prisma/connection";
|
||||
import { generateUUIDv7 } from "../../../helpers/databases/uuidv7";
|
||||
import { SystemAccountId } from "../../../config/account/system";
|
||||
import { Static } from "elysia";
|
||||
import { createHeroBannerSchema } from "../schemas/createHeroBanner.schema";
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
export const insertHeroBannerRepository = async (payload: Static<typeof createHeroBannerSchema.body>) => {
|
||||
export const insertHeroBannerRepository = async (
|
||||
payload: Omit<Prisma.HeroBannerCreateInput, "id" | "createdBy">,
|
||||
) => {
|
||||
try {
|
||||
return await prisma.heroBanner.create({
|
||||
data: {
|
||||
@ -16,9 +16,6 @@ export const insertHeroBannerRepository = async (payload: Static<typeof createHe
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof Prisma.PrismaClientKnownRequestError && error.code === "P2002") {
|
||||
throw new AppError(400, "A hero banner with the order priority already exists", error);
|
||||
}
|
||||
throw new AppError(500, "Failed to insert hero banner", error);
|
||||
}
|
||||
};
|
||||
|
||||
@ -3,18 +3,45 @@ import { AppRouteSchema } from "../../../helpers/types/AppRouteSchema";
|
||||
|
||||
export const createHeroBannerSchema = {
|
||||
body: t.Object({
|
||||
orderPriority: t.Optional(
|
||||
t.Number({ description: "The priority order of the hero banner. Lower numbers indicate higher priority." }),
|
||||
),
|
||||
mediaId: t.String({ description: "The ID of the media associated with the hero banner" }),
|
||||
imageUrl: t.Optional(
|
||||
t.String({
|
||||
description:
|
||||
"The URL of the image used in the hero banner. If not provided, a thumbnail image of the media will be used.",
|
||||
isClickable: t.Optional(
|
||||
t.Boolean({
|
||||
description: "Indicates whether the hero banner is clickable",
|
||||
}),
|
||||
),
|
||||
startDate: t.Date({ description: "The start date for the hero banner in ISO 8601 format" }),
|
||||
endDate: t.Date({ description: "The end date for the hero banner in ISO 8601 format" }),
|
||||
title: t.Optional(
|
||||
t.String({
|
||||
description: "The title of the hero banner",
|
||||
}),
|
||||
),
|
||||
tags: t.Array(t.String(), {
|
||||
description: "An array of tags associated with the hero banner",
|
||||
}),
|
||||
description: t.Optional(
|
||||
t.String({
|
||||
description: "A brief description of the hero banner",
|
||||
}),
|
||||
),
|
||||
buttonContent: t.Optional(
|
||||
t.String({
|
||||
description: "The text content of the button on the hero banner",
|
||||
}),
|
||||
),
|
||||
buttonLink: t.Optional(
|
||||
t.String({
|
||||
description: "The URL that the button on the hero banner links to",
|
||||
}),
|
||||
),
|
||||
imageUrl: t.Optional(
|
||||
t.String({
|
||||
description: "The URL of the image used in the hero banner",
|
||||
}),
|
||||
),
|
||||
startDate: t.String({
|
||||
description: "The start date for the hero banner in ISO 8601 format",
|
||||
}),
|
||||
endDate: t.String({
|
||||
description: "The end date for the hero banner in ISO 8601 format",
|
||||
}),
|
||||
}),
|
||||
detail: {
|
||||
summary: "Create a new hero banner",
|
||||
@ -37,16 +64,17 @@ export const createHeroBannerSchema = {
|
||||
"The created hero banner object. This field is returned only if the environment is running in development mode.",
|
||||
properties: {
|
||||
id: { type: "string", description: "The ID of the created hero banner" },
|
||||
orderPriority: {
|
||||
type: "number",
|
||||
description: "The priority order of the hero banner. Lower numbers indicate higher priority.",
|
||||
},
|
||||
mediaId: { type: "string", description: "The ID of the media associated with the hero banner" },
|
||||
imageUrl: {
|
||||
type: "string",
|
||||
description:
|
||||
"The URL of the image used in the hero banner. If not provided, a thumbnail image of the media will be used.",
|
||||
isClickable: { type: "boolean", description: "Indicates whether the hero banner is clickable" },
|
||||
title: { type: "string", description: "The title of the hero banner" },
|
||||
tags: {
|
||||
type: "array",
|
||||
items: { type: "string" },
|
||||
description: "An array of tags associated with the hero banner",
|
||||
},
|
||||
description: { type: "string", description: "A brief description of the hero banner" },
|
||||
buttonContent: { type: "string", description: "The text content of the button on the hero banner" },
|
||||
buttonLink: { type: "string", description: "The URL that the button on the hero banner links to" },
|
||||
imageUrl: { type: "string", description: "The URL of the image used in the hero banner" },
|
||||
startDate: {
|
||||
type: "string",
|
||||
format: "date-time",
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
import { Static } from "elysia";
|
||||
import { ErrorForwarder } from "../../../../helpers/error/instances/forwarder";
|
||||
import { CreateHeroBannerRequestBody } from "../../controllers/createHeroBanner.controller";
|
||||
import { insertHeroBannerRepository } from "../../repositories/insertHeroBanner.repository";
|
||||
import { createHeroBannerSchema } from "../../schemas/createHeroBanner.schema";
|
||||
|
||||
export const createHeroBannerService = async (payload: Static<typeof createHeroBannerSchema.body>) => {
|
||||
export const createHeroBannerService = async (
|
||||
payload: CreateHeroBannerRequestBody,
|
||||
) => {
|
||||
try {
|
||||
return await insertHeroBannerRepository(payload);
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user