add layers for new image and new game
This commit is contained in:
parent
e9b209edf1
commit
bdd061dd1a
18 changed files with 551 additions and 99 deletions
|
|
@ -46,18 +46,44 @@ async function getExifOrientation(imagePath: string) {
|
|||
})
|
||||
}
|
||||
|
||||
const allImages = () => {
|
||||
const images = fs.readdirSync(UPLOAD_DIR)
|
||||
const allImages = (sort: string) => {
|
||||
let images = fs.readdirSync(UPLOAD_DIR)
|
||||
.filter(f => f.toLowerCase().match(/\.(jpe?g|webp|png)$/))
|
||||
.map(f => ({
|
||||
filename: f,
|
||||
file: `${UPLOAD_DIR}/${f}`,
|
||||
url: `${UPLOAD_URL}/${encodeURIComponent(f)}`,
|
||||
title: '',
|
||||
category: '',
|
||||
ts: fs.statSync(`${UPLOAD_DIR}/${f}`).mtime.getTime(),
|
||||
}))
|
||||
.sort((a, b) => {
|
||||
return fs.statSync(b.file).mtime.getTime() -
|
||||
fs.statSync(a.file).mtime.getTime()
|
||||
})
|
||||
|
||||
switch (sort) {
|
||||
case 'alpha_asc':
|
||||
images = images.sort((a, b) => {
|
||||
return a.file > b.file ? 1 : -1
|
||||
})
|
||||
break;
|
||||
|
||||
case 'alpha_desc':
|
||||
images = images.sort((a, b) => {
|
||||
return a.file < b.file ? 1 : -1
|
||||
})
|
||||
break;
|
||||
|
||||
case 'date_asc':
|
||||
images = images.sort((a, b) => {
|
||||
return a.ts > b.ts ? 1 : -1
|
||||
})
|
||||
break;
|
||||
|
||||
case 'date_desc':
|
||||
default:
|
||||
images = images.sort((a, b) => {
|
||||
return a.ts < b.ts ? 1 : -1
|
||||
})
|
||||
break;
|
||||
}
|
||||
return images
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import GameSockets from './GameSockets'
|
|||
import Time from './../common/Time'
|
||||
import Images from './Images'
|
||||
import { UPLOAD_DIR, UPLOAD_URL, PUBLIC_DIR } from './Dirs'
|
||||
import GameCommon, { ScoreMode } from '../common/GameCommon'
|
||||
import { GameSettings, ScoreMode } from '../common/GameCommon'
|
||||
import GameStorage from './GameStorage'
|
||||
|
||||
let configFile = ''
|
||||
|
|
@ -52,8 +52,10 @@ app.get('/api/conf', (req, res) => {
|
|||
})
|
||||
|
||||
app.get('/api/newgame-data', (req, res) => {
|
||||
const q = req.query as any
|
||||
res.send({
|
||||
images: Images.allImages(),
|
||||
images: Images.allImages(q.sort),
|
||||
categories: [],
|
||||
})
|
||||
})
|
||||
|
||||
|
|
@ -102,16 +104,17 @@ app.post('/upload', (req, res) => {
|
|||
})
|
||||
|
||||
app.post('/newgame', bodyParser.json(), async (req, res) => {
|
||||
log.log(req.body.tiles, req.body.image)
|
||||
const gameSettings = req.body as GameSettings
|
||||
log.log(gameSettings)
|
||||
const gameId = Util.uniqId()
|
||||
if (!Game.exists(gameId)) {
|
||||
const ts = Time.timestamp()
|
||||
await Game.createGame(
|
||||
gameId,
|
||||
req.body.tiles,
|
||||
req.body.image,
|
||||
gameSettings.tiles,
|
||||
gameSettings.image,
|
||||
ts,
|
||||
req.body.scoreMode
|
||||
gameSettings.scoreMode
|
||||
)
|
||||
}
|
||||
res.send({ id: gameId })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue