Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
blinko-space committed Oct 23, 2024
0 parents commit 250db23
Show file tree
Hide file tree
Showing 136 changed files with 24,195 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["next/babel"],
"plugins": [["@babel/plugin-proposal-decorators", { "legacy": true }]]
}
5 changes: 5 additions & 0 deletions .env.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
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
37 changes: 37 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build and Push Docker Image

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Set date as version
run: echo "VERSION=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV

- name: Build Docker image
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile
push: true
no-cache: true
tags: |
dlhtx/blinko:latest
dlhtx/blinko:${{ env.VERSION }}
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
node_modules
.idea
.DS_Store
dist
dist-ssr
*.local
.vscode
out
.next
yarn-error.log
.env
package-lock.json
yarn.lock
*.tsbuildinfo
.scannerwork
.tsbuildinfo
public/robots.txt
public/sitemap*
public/assets
pgdata
upload/*
faiss/*
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"printWidth": 500,
"htmlWhitespaceSensitivity": "ignore",
"singleQuote": true,
"jsxSingleQuote": true,
"bracketSameLine": true,
"proseWrap": "never"
}
41 changes: 41 additions & 0 deletions DEV.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@


## run docker image on server
### export env variables for docker
```
export POSTGRES_USER=postgres
```
### export env variables for docker
```
export POSTGRES_PASSWORD=mysecretpassword
```
### run docker config for docker
```
docker-compose -f docker-compose.prod.yml up -d
```

## build docker with dockerfile locally
```
export POSTGRES_USER=postgres
export POSTGRES_PASSWORD=mysecretpassword
docker build -t blinko .
docker run --name blinko-website -d -p 1111:1111 blinko
```

## test docker with dockerfile locally
```
docker build -t blinko .
docker-compose -f docker-compose.test.yml up -d
```

## 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
```

```
openssl genrsa -out private.pem 2048
openssl req -new -x509 -key private.pem -out cert.pem -days 365
```
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Blinko

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

<img align='right' height='40px' src="./public/single-logo.svg" alt="Blinko" />

# Blinko - Open Source, Self-hosted

Blinko is an innovative open-source project designed for individuals who want to quickly capture and organize their fleeting thoughts. Inspired by the idea of "lightning notes," Blinko allows users to seamlessly jot down ideas the moment they strike, ensuring that no spark of creativity is lost.

What sets Blinko apart is its AI-powered capabilities, offering intelligent suggestions and context-aware enhancements to make your notes more insightful and actionable. Built with a focus on privacy and control, Blinko is fully self-hosted, meaning you can run it on your own server or infrastructure, ensuring your data stays secure and under your ownership.

<img style="border-radius:20px" src="./home.png" alt="Blinko" />



## Main Features
- **AI-Enhanced Note Retrieval** 🤖:With Blinko's advanced AI-powered RAG (Retrieval-Augmented Generation), you can quickly search and access your notes using natural language queries, making it effortless to find exactly what you need.

- **Data Ownership** 🔒:Your privacy matters. All your notes and data are stored securely in your self-hosted environment, ensuring complete control over your information.

- **Efficient and Fast** 🚀:Capture ideas instantly and store them as plain text for easy access, with full Markdown support for quick formatting and seamless sharing.

- **Lightweight Architecture with Heavy Lifting** 💡:Built on Next.js, Blinko offers a sleek, lightweight architecture that delivers robust performance without sacrificing speed or efficiency.

- **Highly Configurable** ⚙️:Personalize Blinko to match your workflow. Customize everything from server name and description to the UI style and execution scripts, making the platform truly your own.

- **Open for Collaboration** 🔓:As an open-source project, Blinko invites contributions from the community. All code is transparent and available on GitHub, fostering a spirit of collaboration and constant improvement.

- **Completely Free** 🎉:Blinko is and always will be free to use, with no hidden costs or premium features locked behind paywalls.

## Deploy with Docker in seconds

```bash
docker-compose -f docker-compose.prod.yml up -d
```

## Contribution
Contributions are the heart of what makes the open-source community so dynamic, creative, and full of learning opportunities. Your involvement helps drive innovation and growth. We deeply value any contribution you make, and we're excited to have you as part of our community. Thank you for your support! 🙌

## Sponsorship
If you find Blinko valuable, consider supporting us! Your contribution will enable us to continue enhancing and maintaining the project for everyone. Thank you for helping us grow!

## Star history

7 changes: 7 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Security Policy

## Reporting a bug

Report security bugs via GitHub [issues]().

For more information, please contact [blinko@gmail.com]().
25 changes: 25 additions & 0 deletions app/api/file/[filename]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { NextRequest, NextResponse } from "next/server";
import path from "path";
import { readFile } from "fs/promises";
import { stat } from "fs/promises";
import mime from "mime-types";

export const GET = async (req: Request, { params }: any) => {
const { filename } = params;
const encodeFileName = encodeURIComponent(filename)
const filePath = path.join(process.cwd(), "upload", encodeFileName);
try {
await stat(filePath);
const fileContent = await readFile(filePath);
const contentType = mime.lookup(filePath) || "application/octet-stream";
return new NextResponse(fileContent, {
headers: {
"Content-Type": contentType,
"Content-Disposition": `attachment; filename="${encodeFileName}"`,
},
});
} catch (error) {
console.log("Error occurred ", error);
return NextResponse.json({ Message: "File not found", status: 404 });
}
};
15 changes: 15 additions & 0 deletions app/api/file/delete/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { remultServer } from "@/server/remult";
import { attachmentsRepo } from "@/server/share/index";
import { unlink } from "fs/promises";
import { NextResponse } from "next/server";
import path from "path";

export const POST = async (req: Request, res: NextResponse) => {
return remultServer.withRemult(async () => {
try {
return NextResponse.json({ Message: "Success", status: 200 });
} catch (error) {
return NextResponse.json({ Message: error?.message ?? "Internal server error", status: 500 });
}
});
};
43 changes: 43 additions & 0 deletions app/api/file/upload/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { NextRequest, NextResponse } from "next/server";
import path from "path";
import { stat, writeFile } from "fs/promises";

const writeFileSafe = async (baseName: string, extension: string, buffer: Buffer) => {
let filename = encodeURIComponent(`${baseName}${extension}`)
try {
const exists = await stat(path.join(process.cwd(), "upload/" + filename));
if (exists) {
baseName = baseName + '_copy';
return await writeFileSafe(baseName, extension, buffer)
}
} catch (error) {
await writeFile(
path.join(process.cwd(), "upload/" + filename),
//@ts-ignore
buffer
);
return filename
}
}

export const POST = async (req: Request, res: NextResponse) => {
const formData = await req.formData();
const file = formData.getAll('file')[0]
if (!file) {
return NextResponse.json({ error: "No files received." }, { status: 400 });
}
//@ts-ignore
const buffer = Buffer.from(await file.arrayBuffer());
//@ts-ignore
const originalName = file.name.replaceAll(" ", "_");
const extension = path.extname(originalName);
const baseName = path.basename(originalName, extension);
try {
const filename = await writeFileSafe(baseName, extension, buffer)
// const filePath = path.join(process.cwd(), "upload/", filename);
return NextResponse.json({ Message: "Success", status: 200, filePath: `/api/file/${filename}`, fileName: filename });
} catch (error) {
console.log("Error occured ", error);
return NextResponse.json({ Message: "Failed", status: 500 });
}
};
54 changes: 54 additions & 0 deletions docker-compose.localtest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# docker-compose.dev.yml

services:
blinko-website:
image: blinko:latest
container_name: blinko-website
environment:
NODE_ENV: production
NEXTAUTH_URL: http://localhost:1111
NEXT_PUBLIC_BASE_URL: http://localhost:1111
NEXT_PUBLIC_PROJECT_ID: blinko
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:
# - ./docker-runtime-dir:/app
- ./public/assets:/app/public/assets
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
container_name: blinko-postgres
restart: always
ports:
- 5432:5432
environment:
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: mysecretpassword
TZ: Asia/Shanghai
# volumes:
# - ./docker-runtime-dir/pgdata:/var/lib/postgresql/data #linux系统中的指定目录
healthcheck:
test:
["CMD", "pg_isready", "-U", "postgres", "-d", "postgres"]
interval: 5s
timeout: 10s
retries: 5
Loading

0 comments on commit 250db23

Please sign in to comment.