Skip to content

Commit

Permalink
Merge pull request #9 from blinko-space/main
Browse files Browse the repository at this point in the history
merge to v2
  • Loading branch information
blinko-space authored Oct 27, 2024
2 parents 1db57bc + 8ea6620 commit 6a10dfc
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 64 deletions.
Binary file removed .blinko/pgdump/bak-v0.0.1.sql
Binary file not shown.
2 changes: 1 addition & 1 deletion .env.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ NEXTAUTH_URL=http://localhost:1111
NEXT_PUBLIC_BASE_URL=http://localhost:1111
NEXTAUTH_SECRET=my_ultra_secure_nextauth_secret
JWT_SECRET=MBqmAZqgbe0I66Jx3sFd/nMoU3paITpHznScerTHJNo2
DATABASE_URL=postgresql://postgres:mysecretpassword@postgres:5435/postgres
DATABASE_URL=postgresql://postgres:mysecretpassword@postgres:5435/postgres
2 changes: 0 additions & 2 deletions DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ docker run --name blinko-website -d -p 1111:1111 blinko

## build docker image & run with docker-compose locally
```
export POSTGRES_USER=postgres
export POSTGRES_PASSWORD=mysecretpassword
docker-compose -f docker-compose.yml up -d --build
```
56 changes: 28 additions & 28 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
# docker-compose.dev.yml

services:
blinko-website:
image: blinkospace/blinko:latest
container_name: blinko-website
environment:
NODE_ENV: production
NEXTAUTH_URL: http://localhost:1111
NEXT_PUBLIC_BASE_URL: http://localhost:1111
NEXTAUTH_SECRET: my_ultra_secure_nextauth_secret
JWT_SECRET: MBqmAZqgbe0I66Jx3sFd/nMoU3paITpHznScerTHJNo2
DATABASE_URL: postgresql://postgres:mysecretpassword@postgres:5432/postgres
depends_on:
postgres:
condition: service_healthy
# volumes:
# - <your volumn>:/app/.blinko
restart: always
logging:
options:
max-size: "10m"
max-file: "3"
ports:
- 1111:1111
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:1111/"]
interval: 30s
timeout: 10s
retries: 5
start_period: 30s
# blinko-website:
# image: blinkospace/blinko:latest
# container_name: blinko-website
# environment:
# NODE_ENV: production
# NEXTAUTH_URL: http://localhost:1111
# NEXT_PUBLIC_BASE_URL: http://localhost:1111
# NEXTAUTH_SECRET: my_ultra_secure_nextauth_secret
# JWT_SECRET: MBqmAZqgbe0I66Jx3sFd/nMoU3paITpHznScerTHJNo2
# DATABASE_URL: postgresql://postgres:mysecretpassword@postgres:5432/postgres
# depends_on:
# postgres:
# condition: service_healthy
# # volumes:
# # - <your volumn>:/app/.blinko
# restart: always
# logging:
# options:
# max-size: "10m"
# max-file: "3"
# ports:
# - 1111:1111
# healthcheck:
# test: ["CMD", "curl", "-f", "http://localhost:1111/"]
# interval: 30s
# timeout: 10s
# retries: 5
# start_period: 30s

postgres:
image: postgres:14
Expand Down
1 change: 0 additions & 1 deletion next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
/// <reference types="next/navigation-types/compat/navigation" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
8 changes: 5 additions & 3 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,19 @@ const prisma = new PrismaClient();
async function main() {
const hasNotes = await prisma.notes.findMany();
if (hasNotes.length == 0) {
const noteRes = await prisma.notes.createManyAndReturn({ data: notes })
await prisma.notes.createMany({ data: notes })
await prisma.tag.createMany({ data: tag })
await prisma.tagsToNote.createMany({ data: tagsToNote })
await prisma.attachments.createMany({ data: attachments })
return noteRes
await prisma.$executeRaw`SELECT setval('notes_id_seq', (SELECT MAX(id) FROM "notes") + 1);`
await prisma.$executeRaw`SELECT setval('tag_id_seq', (SELECT MAX(id) FROM "tag") + 1);`
await prisma.$executeRaw`SELECT setval('"tagsToNote_id_seq"', (SELECT MAX(id) FROM "tagsToNote") + 1);`
await prisma.$executeRaw`SELECT setval('attachments_id_seq', (SELECT MAX(id) FROM "attachments") + 1);`
}
}

main()
.then(e => {
console.log(e)
console.log("✨ Seed done! ✨")
})
.catch((e) => {
Expand Down
13 changes: 10 additions & 3 deletions src/components/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import { BlinkoAi } from "../BlinkoAi";
import { ScrollArea } from "../Common/ScrollArea";
import { BlinkoNewVersion } from "../BlinkoNewVersion";

const documentHeight = () => {
const doc = document.documentElement
doc.style.setProperty('--doc-height', `${window.innerHeight}px`)
}

export const SideBarItem = "p-2 flex flex-row items-center cursor-pointer gap-2 hover:bg-hover hover:bg-hover-foreground rounded-xl transition-all"
export const CommonLayout = observer(({
children,
Expand All @@ -40,6 +45,8 @@ export const CommonLayout = observer(({
useEffect(() => {
base.changeLanugage(i18n, base.locale.value)
setIsClient(true)
documentHeight()
window.addEventListener('resize', documentHeight)
debounceSearch = _.debounce(() => {
blinkoStore.noteList.resetAndCall({})
})
Expand Down Expand Up @@ -89,7 +96,7 @@ export const CommonLayout = observer(({
);

return (
<div className="flex h-dvh w-full">
<div className="flex w-full h-mobile-full">
{
blinkoStore.showAi && <BlinkoAi />
}
Expand Down Expand Up @@ -123,7 +130,7 @@ export const CommonLayout = observer(({
fullWidth
variant="flat"
aria-label="search"
className="ml-auto"
className={`ml-auto w-[150px] md:w-[300px]`}
classNames={{
base: "px-1 mr-1 w-[full] md:w-[300px]",
inputWrapper:
Expand Down Expand Up @@ -165,7 +172,7 @@ export const CommonLayout = observer(({


{/* main container */}
<ScrollArea onBottom={() => { }} className="flex h-[calc(100%_-_100px)] overflow-y-scroll scroll-container">
<ScrollArea onBottom={() => { }} className="flex h-[calc(100%_-_70px)] overflow-y-scroll scroll-container">
<div className="flex h-full w-full flex-col rounded-medium" >
{children}
</div>
Expand Down
9 changes: 4 additions & 5 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const Home = observer(({ type, isArchived }: { type?: number | null, isArchived?
}, [type, tagId])

const store = RootStore.Local(() => ({
editorHeight: 90,
editorHeight: 75,
get showEditor() {
return !isArchived
},
Expand All @@ -60,7 +60,7 @@ const Home = observer(({ type, isArchived }: { type?: number | null, isArchived?

return (
<div className="md:p-0 relative h-full flex flex-col-reverse md:flex-col">
{store.showEditor && <div className='px-2 md:px-6 ' >
{store.showEditor && <div className='px-2 md:px-6' >
<BlinkoEditor mode='create' key='create-key' onHeightChange={height => store.editorHeight = height} />
</div>}
<div className='text-ignore flex items-center justify-center gap-1 w-full '>
Expand All @@ -77,7 +77,7 @@ const Home = observer(({ type, isArchived }: { type?: number | null, isArchived?
!blinko.noteList.isEmpty && <ScrollArea
onBottom={() => blinko.onBottom()}
style={{ height: store.showEditor ? `calc(100vh - ${100 + store.editorHeight}px)` : '100vh' }}
className={`px-2 mt-0 md:mt-6 md:px-6 w-full h-full transition-all`}>
className={`px-2 mt-0 md:mt-6 md:px-6 w-full h-full transition-all scroll-area`}>
<Masonry
breakpointCols={{
default: 2,
Expand Down Expand Up @@ -125,10 +125,9 @@ const Home = observer(({ type, isArchived }: { type?: number | null, isArchived?
})
}
</Masonry>
{store.showLoadAll && <div className='w-full text-center text-sm font-bold text-ignore mt-4'>{t('all-notes-have-been-loaded', { items: blinko.noteList.value?.length })}</div>}
{store.showLoadAll && <div className='w-full text-center text-sm font-bold text-ignore my-4'>{t('all-notes-have-been-loaded', { items: blinko.noteList.value?.length })}</div>}
</ScrollArea>
}

<BlinkoRightClickMenu />
<BlinkoMultiSelectPop />
</div>
Expand Down
24 changes: 4 additions & 20 deletions src/server/plugins/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { unlink } from "fs/promises";
export const Backupdb = async () => {
try {
// console.log(`pg_dump --dbname=${process.env.DATABASE_URL!} --format=custom --file=${DBBAKUP_PATH}/bak-v${Package.version}.sql --data-only --exclude-table=_prisma_migrations`)
const { stdout, stderr } = await $`pg_dump --dbname=${process.env.DATABASE_URL!} --format=custom --file=${DBBAKUP_PATH}/bak-v${Package.version}.sql --data-only
const { stdout, stderr } = await $`pg_dump --dbname=${process.env.DATABASE_URL!} --format=custom --file=${DBBAKUP_PATH}/bak.sql --data-only
--exclude-table=accounts --exclude-table=scheduledTask --exclude-table=_prisma_migrations`;
// console.log({ stdout, stderr })
if (stderr) {
Expand All @@ -34,35 +34,19 @@ export const Backupdb = async () => {
}

export const Resotredb = async (filePath) => {
console.log(UPLOAD_FILE_PATH + '/' + filePath)
const zip = new AdmZip(UPLOAD_FILE_PATH + '/' + filePath);
zip.extractAllTo(ROOT_PATH, true);
const sqlFile = findFirstSQLFile(ROOT_PATH)
if (!sqlFile) {
const exists = fs.existsSync('.blinko/pgdump/bak.sql')
if (!exists) {
throw new Error("Your db file can not find restore file")
}
const { stdout, stderr } = await $`pg_restore --dbname=${process.env.DATABASE_URL!} ${sqlFile.replace(/\\/g, '/')}`;
const { stdout, stderr } = await $`pg_restore --dbname=${process.env.DATABASE_URL!} .blinko/pgdump/bak.sql}`;
if (stderr) {
throw new Error(stderr)
}
return true
}

const findFirstSQLFile = (dir) => {
const files = fs.readdirSync(dir);
for (const file of files) {
const filePath = path.join(dir, file);
const stat = fs.statSync(filePath);
if (stat.isDirectory()) {
const found = findFirstSQLFile(filePath);
if (found) return found;
} else if (path.extname(file) === '.sql') {
return path.normalize(filePath);
}
}
return null;
}

export const DBBackupJob = new CronJob('* * * * *', async () => {
try {
const res = await Backupdb()
Expand Down
6 changes: 5 additions & 1 deletion src/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@
html,
body {
scroll-behavior: smooth;
height: 100%;
overflow-y: hidden;
height: var(--doc-height);
}

.h-mobile-full {
height: var(--doc-height);
}


Expand Down

0 comments on commit 6a10dfc

Please sign in to comment.