mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-23 15:51:01 +08:00
feat: implement go_links table and update database connection handling
This commit is contained in:
parent
4aab557523
commit
1208866757
@ -1,4 +1,4 @@
|
|||||||
import { sql } from "bun";
|
import sql from "~/server/components/postgres";
|
||||||
|
|
||||||
const createUsers = await sql`
|
const createUsers = await sql`
|
||||||
create table if not exists users (
|
create table if not exists users (
|
||||||
@ -42,6 +42,17 @@ create table if not exists newsProvidersZh (
|
|||||||
)
|
)
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|
||||||
|
const createGoLinks = await sql`
|
||||||
|
create table if not exists go_links {
|
||||||
|
uuid text primary key,
|
||||||
|
title text,
|
||||||
|
slug text unique not null,
|
||||||
|
forwardUrl text not null,
|
||||||
|
created_at timestampz default current_timestamp
|
||||||
|
}
|
||||||
|
`
|
||||||
|
/*
|
||||||
const createAdminPosts = await sql`
|
const createAdminPosts = await sql`
|
||||||
create table if not exists adminPosts (
|
create table if not exists adminPosts (
|
||||||
uuid text primary key,
|
uuid text primary key,
|
||||||
@ -59,6 +70,6 @@ create table if not exists adminUsers (
|
|||||||
created_at timestampz default current_timestamp,
|
created_at timestampz default current_timestamp,
|
||||||
lastlogged_at timestampz default current_timestamp,
|
lastlogged_at timestampz default current_timestamp,
|
||||||
)
|
)
|
||||||
`;
|
`;*/
|
||||||
|
|
||||||
console.log("Creation Complete");
|
console.log("Creation Complete");
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
<script lang="ts" setup>
|
|
||||||
definePageMeta({
|
|
||||||
layout: "admin",
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
<template>
|
|
||||||
<div class="flex justify-center min-h-screen w-full">
|
|
||||||
<input type="text" />
|
|
||||||
<input type="password" />
|
|
||||||
<button>登入</button>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
7
server/components/postgres.ts
Normal file
7
server/components/postgres.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { SQL } from "bun";
|
||||||
|
|
||||||
|
const postgres = new SQL({
|
||||||
|
url: process.env.POSTGRES_URL,
|
||||||
|
})
|
||||||
|
|
||||||
|
export default postgres;
|
@ -0,0 +1,24 @@
|
|||||||
|
import sql from "~/server/components/postgres";
|
||||||
|
export default defineEventHandler(async (event) => {
|
||||||
|
const slug = getRouterParam(event, 'slug');
|
||||||
|
if (!slug || typeof slug !== 'string') {
|
||||||
|
throw createError({
|
||||||
|
statusCode: 400,
|
||||||
|
message: 'Invalid slug parameter'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const cleanSlug = slug.replace(/[^a-zA-Z0-9-_]/g, '');
|
||||||
|
try {
|
||||||
|
const result = await sql`
|
||||||
|
select * from go_links
|
||||||
|
where slug = ${cleanSlug}
|
||||||
|
`
|
||||||
|
return result.rows[0] || null;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Database error:', error);
|
||||||
|
throw createError({
|
||||||
|
statusCode: 500,
|
||||||
|
message: 'Internal server error'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
Loading…
x
Reference in New Issue
Block a user