build
This commit is contained in:
parent
65daeb0247
commit
1008106355
4 changed files with 54 additions and 4 deletions
File diff suppressed because one or more lines are too long
1
build/public/assets/index.cbfa449f.js
Normal file
1
build/public/assets/index.cbfa449f.js
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -4,7 +4,7 @@
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
|
||||||
<title>🧩 jigsaw.hyottoko.club</title>
|
<title>🧩 jigsaw.hyottoko.club</title>
|
||||||
<script type="module" crossorigin src="/assets/index.90925b20.js"></script>
|
<script type="module" crossorigin src="/assets/index.cbfa449f.js"></script>
|
||||||
<link rel="modulepreload" href="/assets/vendor.684f7bc8.js">
|
<link rel="modulepreload" href="/assets/vendor.684f7bc8.js">
|
||||||
<link rel="stylesheet" href="/assets/index.22dc307c.css">
|
<link rel="stylesheet" href="/assets/index.22dc307c.css">
|
||||||
</head>
|
</head>
|
||||||
|
|
|
||||||
|
|
@ -610,12 +610,16 @@ function setEvtInfo(gameId, playerId, evtInfo) {
|
||||||
}
|
}
|
||||||
function getAllGames() {
|
function getAllGames() {
|
||||||
return Object.values(GAMES).sort((a, b) => {
|
return Object.values(GAMES).sort((a, b) => {
|
||||||
|
const finished = isFinished(a.id);
|
||||||
// when both have same finished state, sort by started
|
// when both have same finished state, sort by started
|
||||||
if (isFinished(a.id) === isFinished(b.id)) {
|
if (finished === isFinished(b.id)) {
|
||||||
|
if (finished) {
|
||||||
|
return b.puzzle.data.finished - a.puzzle.data.finished;
|
||||||
|
}
|
||||||
return b.puzzle.data.started - a.puzzle.data.started;
|
return b.puzzle.data.started - a.puzzle.data.started;
|
||||||
}
|
}
|
||||||
// otherwise, sort: unfinished, finished
|
// otherwise, sort: unfinished, finished
|
||||||
return isFinished(a.id) ? 1 : -1;
|
return finished ? 1 : -1;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function getAllPlayers(gameId) {
|
function getAllPlayers(gameId) {
|
||||||
|
|
@ -1439,6 +1443,7 @@ const imageFromDb = (db, imageId) => {
|
||||||
const i = db.get('images', { id: imageId });
|
const i = db.get('images', { id: imageId });
|
||||||
return {
|
return {
|
||||||
id: i.id,
|
id: i.id,
|
||||||
|
uploaderUserId: i.uploader_user_id,
|
||||||
filename: i.filename,
|
filename: i.filename,
|
||||||
url: `${UPLOAD_URL}/${encodeURIComponent(i.filename)}`,
|
url: `${UPLOAD_URL}/${encodeURIComponent(i.filename)}`,
|
||||||
title: i.title,
|
title: i.title,
|
||||||
|
|
@ -1477,6 +1482,7 @@ inner join images i on i.id = ixc.image_id ${where.sql};
|
||||||
const images = db.getMany('images', wheresRaw, orderByMap[orderBy]);
|
const images = db.getMany('images', wheresRaw, orderByMap[orderBy]);
|
||||||
return images.map(i => ({
|
return images.map(i => ({
|
||||||
id: i.id,
|
id: i.id,
|
||||||
|
uploaderUserId: i.uploader_user_id,
|
||||||
filename: i.filename,
|
filename: i.filename,
|
||||||
url: `${UPLOAD_URL}/${encodeURIComponent(i.filename)}`,
|
url: `${UPLOAD_URL}/${encodeURIComponent(i.filename)}`,
|
||||||
title: i.title,
|
title: i.title,
|
||||||
|
|
@ -1494,6 +1500,7 @@ const allImagesFromDisk = (tags, sort) => {
|
||||||
.filter(f => f.toLowerCase().match(/\.(jpe?g|webp|png)$/))
|
.filter(f => f.toLowerCase().match(/\.(jpe?g|webp|png)$/))
|
||||||
.map(f => ({
|
.map(f => ({
|
||||||
id: 0,
|
id: 0,
|
||||||
|
uploaderUserId: null,
|
||||||
filename: f,
|
filename: f,
|
||||||
url: `${UPLOAD_URL}/${encodeURIComponent(f)}`,
|
url: `${UPLOAD_URL}/${encodeURIComponent(f)}`,
|
||||||
title: f.replace(/\.[a-z]+$/, ''),
|
title: f.replace(/\.[a-z]+$/, ''),
|
||||||
|
|
@ -2093,6 +2100,16 @@ const storage = multer.diskStorage({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const upload = multer({ storage }).single('file');
|
const upload = multer({ storage }).single('file');
|
||||||
|
app.get('/api/me', (req, res) => {
|
||||||
|
let user = db.get('users', {
|
||||||
|
'client_id': req.headers['client-id'],
|
||||||
|
'client_secret': req.headers['client-secret'],
|
||||||
|
});
|
||||||
|
res.send({
|
||||||
|
id: user ? user.id : null,
|
||||||
|
created: user ? user.created : null,
|
||||||
|
});
|
||||||
|
});
|
||||||
app.get('/api/conf', (req, res) => {
|
app.get('/api/conf', (req, res) => {
|
||||||
res.send({
|
res.send({
|
||||||
WS_ADDRESS: config.ws.connectstring,
|
WS_ADDRESS: config.ws.connectstring,
|
||||||
|
|
@ -2164,7 +2181,24 @@ const setImageTags = (db, imageId, tags) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
app.post('/api/save-image', express.json(), (req, res) => {
|
app.post('/api/save-image', express.json(), (req, res) => {
|
||||||
|
let user = db.get('users', {
|
||||||
|
'client_id': req.headers['client-id'],
|
||||||
|
'client_secret': req.headers['client-secret'],
|
||||||
|
});
|
||||||
|
let userId = null;
|
||||||
|
if (user) {
|
||||||
|
userId = parseInt(user.id, 10);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res.status(403).send({ ok: false, error: 'forbidden' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
const data = req.body;
|
const data = req.body;
|
||||||
|
let image = db.get('images', { id: data.id });
|
||||||
|
if (parseInt(image.uploader_user_id, 10) !== userId) {
|
||||||
|
res.status(403).send({ ok: false, error: 'forbidden' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
db.update('images', {
|
db.update('images', {
|
||||||
title: data.title,
|
title: data.title,
|
||||||
}, {
|
}, {
|
||||||
|
|
@ -2189,8 +2223,24 @@ app.post('/api/upload', (req, res) => {
|
||||||
log.log(err);
|
log.log(err);
|
||||||
res.status(400).send("Something went wrong!");
|
res.status(400).send("Something went wrong!");
|
||||||
}
|
}
|
||||||
|
let user = db.get('users', {
|
||||||
|
'client_id': req.headers['client-id'],
|
||||||
|
'client_secret': req.headers['client-secret'],
|
||||||
|
});
|
||||||
|
let userId = null;
|
||||||
|
if (user) {
|
||||||
|
userId = user.id;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
userId = db.insert('users', {
|
||||||
|
'client_id': req.headers['client-id'],
|
||||||
|
'client_secret': req.headers['client-secret'],
|
||||||
|
'created': Time.timestamp(),
|
||||||
|
});
|
||||||
|
}
|
||||||
const dim = await Images.getDimensions(`${UPLOAD_DIR}/${req.file.filename}`);
|
const dim = await Images.getDimensions(`${UPLOAD_DIR}/${req.file.filename}`);
|
||||||
const imageId = db.insert('images', {
|
const imageId = db.insert('images', {
|
||||||
|
uploader_user_id: userId,
|
||||||
filename: req.file.filename,
|
filename: req.file.filename,
|
||||||
filename_original: req.file.originalname,
|
filename_original: req.file.originalname,
|
||||||
title: req.body.title || '',
|
title: req.body.title || '',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue