init commit,

This commit is contained in:
louiscklaw
2025-05-28 09:55:51 +08:00
commit efe70ceb69
8042 changed files with 951668 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
import type { NextRequest } from 'next/server';
import { logger } from 'src/utils/logger';
import { STATUS, response, handleError } from 'src/utils/response';
import { _mails } from 'src/_mock/_mail';
// ----------------------------------------------------------------------
export const runtime = 'edge';
/** **************************************
* GET - Mail details
*************************************** */
export async function GET(req: NextRequest) {
try {
const { searchParams } = req.nextUrl;
const mailId = searchParams.get('mailId');
const mails = _mails();
const mail = mails.find((mailItem) => mailItem.id === mailId);
if (!mail) {
return response({ message: 'Mail not found!' }, STATUS.NOT_FOUND);
}
logger('[Mail] details', mail.id);
return response({ mail }, STATUS.OK);
} catch (error) {
return handleError('Mail - Get details', error);
}
}

View File

@@ -0,0 +1,23 @@
import { logger } from 'src/utils/logger';
import { STATUS, response, handleError } from 'src/utils/response';
import { _labels } from 'src/_mock/_mail';
// ----------------------------------------------------------------------
export const runtime = 'edge';
/** **************************************
* GET - Labels
*************************************** */
export async function GET() {
try {
const labels = _labels();
logger('[Mail] labels', labels.length);
return response({ labels }, STATUS.OK);
} catch (error) {
return handleError('Mail - Get labels', error);
}
}

View File

@@ -0,0 +1,57 @@
import type { NextRequest } from 'next/server';
import { logger } from 'src/utils/logger';
import { STATUS, response, handleError } from 'src/utils/response';
import { _mails, _labels } from 'src/_mock/_mail';
// ----------------------------------------------------------------------
export const runtime = 'edge';
type MailType = ReturnType<typeof _mails>[number];
/** **************************************
* GET - Mails by labelId
*************************************** */
export async function GET(req: NextRequest) {
try {
const { searchParams } = req.nextUrl;
const labelId = searchParams.get('labelId');
const labels = _labels();
const mails = _mails();
logger('[Mail] labelId', labelId);
const label = labels.find((labelItem) => labelItem.id === labelId);
if (!label) {
return response({ message: 'Label not found!' }, STATUS.NOT_FOUND);
}
// Get filtered mails
const filteredMails =
label.type === 'custom'
? mails.filter((mail) => mail.labelIds.includes(labelId!))
: filterMailsByLabelId(mails, labelId);
logger(`[Mail] label-[${labelId}]`, filteredMails.length);
return response({ mails: filteredMails }, STATUS.OK);
} catch (error) {
return handleError('Mail - Get list', error);
}
}
/** **************************************
* Actions & Utility
*************************************** */
function filterMailsByLabelId(mails: MailType[], labelId?: string | null) {
if (!labelId || labelId === 'inbox') return mails.filter((mail) => mail.folder === 'inbox');
if (labelId === 'all') return mails;
if (labelId === 'starred') return mails.filter((mail) => mail.isStarred);
if (labelId === 'important') return mails.filter((mail) => mail.isImportant);
return mails.filter((mail) => mail.folder === labelId);
}