Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sylvie's repo into apps/ui and remove git relations respectively #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
661 changes: 0 additions & 661 deletions apps/ui/LICENSE

This file was deleted.

36 changes: 36 additions & 0 deletions apps/ui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
137 changes: 137 additions & 0 deletions apps/ui/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import * as fs from 'fs';

let _db = {
conversations: []
}

try {
_db = JSON.parse(fs.readFileSync('./db.json'));
} catch {}

function createProxy(target, prop) {
if (typeof target[prop] == 'object') {
if (Array.isArray(target[prop])) {
if (target[prop].push.toString().includes('native code')) {
target[prop].push = new Proxy(target[prop].push, {
apply(t, g, a) {
var a = Reflect.apply(t, g, a)

saveDB()

return a;
}
})

target[prop].push.toString = () => "nah"
}

return target[prop]
}

return new Proxy(target[prop], {
get(target, prop) {
return createProxy(target, prop)
},
set(target, prop, value) {
Reflect.set(target, prop, value)

saveDB()

return value;
}
})
} else {
return target[prop]
}
}

function saveDB() {
fs.writeFileSync('./db.json', JSON.stringify(_db))
}

const db = new Proxy(_db, {
get(target, prop) {
return createProxy(target, prop)
},
set(target, prop, value) {
Reflect.set(target, prop, value)

saveDB()

return value;
}
})

function id(num) {
let seg = () => Math.floor(Math.random() * 1e+10).toString(19)

return Array.from('*'.repeat(num)).map(e => seg()).join('-')
}

const api = async (req, res) => {
if (req.method === 'OPTIONS') {
res.setHeader('Access-Control-Allow-Origin', '*')
res.setHeader('Access-Control-Allow-Methods', 'POST, GET, OPTIONS')
res.setHeader('Access-Control-Allow-Headers', 'Content-Type')
return res.end()
}

res.setHeader('Access-Control-Allow-Origin', '*')

if (req.method === 'GET') {
if (req.url === '/api/conversations/all') {
res.setHeader('Content-Type', 'application/json')
return res.end(JSON.stringify(db.conversations.map(e => ({
name: e.name,
id: e.id,
created: e.created,
lastMessage: e.lastMessage
}))))
}
}

if (req.method !== 'POST') {
res.statusCode = 405
return res.end('Method Not Allowed')
}

const chunks = []
for await (const chunk of req) {
chunks.push(chunk)
}

const body = Buffer.concat(chunks).toString()

if (req.url === '/api/conversations/get') {
const data = JSON.parse(body);
const conversation = db.conversations.find(c => c.id === data.id)
res.setHeader('Content-Type', 'application/json')
return res.end(JSON.stringify(conversation))
}
if (req.url === '/api/conversations/create') {
const conversation = JSON.parse(body)
conversation.id = id(4)
conversation.created = Date.now()
conversation.lastMessage = Date.now()
db.conversations.push(conversation)
res.setHeader('Content-Type', 'application/json')
return res.end(JSON.stringify(conversation))
}
if (req.url === '/api/conversations/save') {
const conversation = JSON.parse(body);
const { id } = conversation;
const index = db.conversations.findIndex(convo => convo.id === id);

db.conversations[index] = conversation

saveDB()

res.setHeader('Content-Type', 'application/json')
return res.end(JSON.stringify({'success': true}))
}

res.statusCode = 404
res.end('Not Found')
}

export default api
Empty file removed apps/ui/app/components/chat.tsx
Empty file.
111 changes: 0 additions & 111 deletions apps/ui/app/components/landing.tsx

This file was deleted.

Empty file removed apps/ui/app/components/menu.tsx
Empty file.
Empty file.
57 changes: 0 additions & 57 deletions apps/ui/app/components/ui/button.tsx

This file was deleted.

Loading