wip (idk if this will go anywhere)

This commit is contained in:
flash 2024-10-23 22:07:03 +00:00
parent 792cf74367
commit 956402ca97
3 changed files with 1034 additions and 2 deletions

955
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,7 @@
{ {
"dependencies": { "dependencies": {
"cheerio": "^1.0.0" "cheerio": "^1.0.0",
"express": "^5.0.1",
"memcache-client": "^1.0.5"
} }
} }

77
uiharu.js Normal file
View file

@ -0,0 +1,77 @@
const express = require('express');
const fs = require('fs');
const memcache = require('memcache-client');
const { join: pathJoin } = require('path');
// todo: these should not be hardcoded lol
const port = 3009;
const memcacheServer = "localhost:11211";
const allowedOrigins = [
'edgii.net',
'chat.edgii.net',
'sockchat.edgii.net',
'ajaxchat.edgii.net',
];
const app = express();
const isDebug = fs.existsSync(pathJoin(__dirname, '.debug'));
const cache = new memcache.MemcacheClient({ server: memcacheServer });
const handleMetadata = (res, req, url) => {
//
};
app.use((req, res, next) => {
res.set('X-Powered-By', 'Uiharu');
const origin = req.get('origin');
if(origin !== undefined) {
const originObj = new URL(origin);
if(!allowedOrigins.includes(originObj.host)) {
res.status(403).end();
return;
}
res.set('Access-Control-Allow-Origin', origin);
res.set('Vary', 'Origin');
}
if(req.method === 'OPTIONS')
res.set('Access-Control-Allow-Methods', 'OPTIONS, GET, POST');
next();
});
app.use(express.static('public'));
app.get('/metadata', (req, res) => {
res.status(501).send('Not Implemented');
});
app.post('/metadata', (req, res) => {
res.status(501).send('Not Implemented');
});
app.get('/metadata/batch', (req, res) => {
res.type('application/json')
.send('{"took":0,"results":[]}')
.end();
});
app.post('/metadata/batch', (req, res) => {
res.type('application/json')
.send('{"took":0,"results":[]}')
.end();
});
app.get('/metadata/thumb/audio', (req, res) => {
res.status(501).send('Not Implemented');
});
app.get('/metadata/thumb/video', (req, res) => {
res.status(501).send('Not Implemented');
});
app.listen(port, () => {
console.log(`Uiharu listening to port ${port}!`);
});