Content Migration from websites repo
This commit is contained in:
parent
4b0bd40dcf
commit
5869e05c33
49 changed files with 9081 additions and 1 deletions
pages/api
16
pages/api/[map].tsx
Normal file
16
pages/api/[map].tsx
Normal file
|
@ -0,0 +1,16 @@
|
|||
import fsPromises from 'fs/promises'
|
||||
import path from 'path'
|
||||
|
||||
export default async function MapApi(req: any, res: any) {
|
||||
const { map } = req.query
|
||||
try {
|
||||
// get Empire and Game name first to create an EmpireData object
|
||||
const filePathMap = path.join(process.cwd(), '/public/images/'+map+'/info.json');
|
||||
const jsonMapData = await fsPromises.readFile(filePathMap);
|
||||
res.status(200).send(jsonMapData.toString())
|
||||
}
|
||||
catch (error) {
|
||||
console.log(error)
|
||||
res.status(500).json({error: 'Error reading data'})
|
||||
}
|
||||
}
|
23
pages/api/[map]/maps.tsx
Normal file
23
pages/api/[map]/maps.tsx
Normal file
|
@ -0,0 +1,23 @@
|
|||
import fsPromises from 'fs/promises'
|
||||
import path from 'path'
|
||||
|
||||
export default async function MapApi(req: any, res: any) {
|
||||
const { map } = req.query
|
||||
try {
|
||||
// get list of all files(maps) in the readyornot folder - maybe there is a cleaner way to do this?
|
||||
// we filter out any subdirectories as well as any files not ending in png or jpg
|
||||
var fs = require('fs')
|
||||
var maps = fs.readdirSync(path.join(process.cwd(), "/public/images/" + map + "/"), { withFileTypes: true })
|
||||
.filter((file: any) => file.isFile())
|
||||
.filter((file: any) => file.name.endsWith(".jpg") || file.name.endsWith(".png"))
|
||||
.map((file: any) => '/images/' + map + '/' + file.name);
|
||||
|
||||
|
||||
// get Empire and Game name first to create an EmpireData object
|
||||
res.status(200).json(maps)
|
||||
}
|
||||
catch (error) {
|
||||
console.log(error)
|
||||
res.status(500).json({ error: 'Error reading data' })
|
||||
}
|
||||
}
|
33
pages/api/navbar.tsx
Normal file
33
pages/api/navbar.tsx
Normal file
|
@ -0,0 +1,33 @@
|
|||
// jsut iterate through all relevant data serverside instead of dealing with it client side
|
||||
import fsPromises from 'fs/promises'
|
||||
import path from 'path'
|
||||
import ReadyOrNotMap from '../../interfaces/ReadyOrNot'
|
||||
|
||||
export default async function TobarApi(req: any, res: any) {
|
||||
try {
|
||||
// get list of all folders(maps) in the readyornot folder - maybe there is a cleaner way to do this?
|
||||
var fs = require('fs')
|
||||
var mapList = fs.readdirSync(path.join(process.cwd(), '/public/images/'), { withFileTypes: true })
|
||||
.filter((dirent:any) => dirent.isDirectory())
|
||||
.map((dirent:any) => dirent.name);
|
||||
|
||||
// iterate through every map entry and extract the info
|
||||
let maps: ReadyOrNotMap[] = [];
|
||||
|
||||
for (let i = 0; i < mapList.length; i++) {
|
||||
// get map data for the API request
|
||||
const filePathEmpire = path.join(process.cwd(), '/public/images/' + mapList[i] + '/info.json');
|
||||
const jsonDataEmpire = await fsPromises.readFile(filePathEmpire);
|
||||
let mapData = JSON.parse(jsonDataEmpire.toString());
|
||||
mapData.href = mapList[i];
|
||||
|
||||
maps.push(mapData) ;
|
||||
}
|
||||
|
||||
res.status(200).json(maps);
|
||||
}
|
||||
catch (error) {
|
||||
console.log(error);
|
||||
res.status(500).json({ error: 'Error reading data' });
|
||||
}
|
||||
}
|
Reference in a new issue