License system implemented

This commit is contained in:
2024-11-25 18:55:28 +01:00
parent 1b0f48d374
commit 2e15d4a960
22 changed files with 313 additions and 18 deletions

182
backend/data/licenses.json Normal file
View File

@@ -0,0 +1,182 @@
[
{
"image": "alex-turner.jpg",
"license": "CC BY 2.0",
"creator": "Raph_PH",
"url": "https://upload.wikimedia.org/wikipedia/commons/9/95/Alex_Turner%2C_Way_Out_West_2018.jpg"
},
{
"image": "andy-nicholson.jpg",
"license": "CC BY 2.0",
"creator": "Lola's Big Adventure!",
"url": "https://upload.wikimedia.org/wikipedia/commons/6/6c/Andy_Nicholson_%28cropped%29.jpg"
},
{
"image": "anthony-kiedis.jpg",
"license": "CC BY 2.0",
"creator": "Hel Davies",
"url": "https://upload.wikimedia.org/wikipedia/commons/c/ca/Anthony_Kiedis_2022.jpg"
},
{
"image": "chris-martin.jpg",
"license": "CC BY 2.0",
"creator": "Raph_PH",
"url": "https://upload.wikimedia.org/wikipedia/commons/6/68/ChrisMartinManch030623_%28cropped%29.jpg"
},
{
"image": "chris-wolstenholme.jpg",
"license": "CC BY-SA 4.0",
"creator": "Markus Felix",
"url": "https://upload.wikimedia.org/wikipedia/commons/e/eb/2018_Chris_Wolstenholme_%28cropped%29.jpg"
},
{
"image": "flea.jpg",
"license": "CC BY 2.0",
"creator": "Piyush Kumar",
"url": "https://upload.wikimedia.org/wikipedia/commons/8/8e/Flea_1012_%282%29.jpg"
},
{
"image": "chad-smith.jpg",
"license": "Gemeinfrei",
"creator": "Bojosoto",
"url": "https://upload.wikimedia.org/wikipedia/commons/4/42/Chadsmithclinic.jpg"
},
{
"image": "john-frusciante.jpg",
"license": "CC BY-SA 2.0",
"creator": "Hel Davies",
"url": "https://upload.wikimedia.org/wikipedia/commons/1/1f/John_Frusciante_%2852279466415%29.jpg"
},
{
"image": "logo.png",
"license": "MIT",
"creator": "Tobias Zoghaib",
"url": ""
},
{
"image": "lanxess-arena-indoor.jpg",
"license": "CC BY-SA 3.0",
"creator": "Admin Kübelbeck",
"url": "https://upload.wikimedia.org/wikipedia/commons/f/f3/Koelnarena_inside.jpg"
},
{
"image": "lanxess-arena-outdoor.jpg",
"license": "CC BY-SA 2.0",
"creator": "Rolf H.",
"url": "https://upload.wikimedia.org/wikipedia/commons/1/18/Lanxess_Arena_Flight_over_Cologne.jpg"
},
{
"image": "red-hot-chili-peppers-1.jpg",
"license": "CC BY-SA 4.0",
"creator": "Kreepin Deth",
"url": "https://upload.wikimedia.org/wikipedia/commons/1/14/RHCP_Live_in_London_26_June_2022.jpg"
},
{
"image": "swiss-life-hall-indoor.jpg",
"license": "CC BY-SA 3.0",
"creator": "Bernd Schwabe in Hannover",
"url": "https://upload.wikimedia.org/wikipedia/commons/8/89/2013-09-18_Besuch_14._Dalai_Lama_Tendzin_Gyatsho_in_Hannover%2C_future4children%2C_Swiss_Life_Hall%2C_%2876%29.JPG"
},
{
"image": "swiss-life-hall-outdoor.jpg",
"license": "Public Domain",
"creator": "AxelHH",
"url": "https://upload.wikimedia.org/wikipedia/commons/6/66/AWD_Hall_Seite.jpg"
},
{
"image": "astra-kulturhaus-outdoor.jpg",
"license": "CC BY 2.0",
"creator": "Marcus Grbac",
"url": "https://upload.wikimedia.org/wikipedia/commons/f/fd/Astra_Kulturhaus_Biergarten_RAW_Berlin_July_2017.jpg"
},
{
"image": "thom-yorke.jpg",
"license": "CC BY 2.0",
"creator": "Raph_PH",
"url": "https://upload.wikimedia.org/wikipedia/commons/2/25/RadioheadMontreal170718-70_%2843600493681%29_%28cropped%29.jpg"
},
{
"image": "rami-jaffee.jpg",
"license": "CC BY 2.0",
"creator": "Raph_PH",
"url": "https://upload.wikimedia.org/wikipedia/commons/f/fa/Rami_Jaffee_1.jpg"
},
{
"image": "philip-selway.jpg",
"license": "CC BY-SA 2.0",
"creator": "Michell Zappa",
"url": "https://upload.wikimedia.org/wikipedia/commons/1/1f/Phil_Selway.jpg"
},
{
"image": "phil-harvey.jpg",
"license": "CC BY-SA 3.0",
"creator": "Hayley St. James",
"url": "https://upload.wikimedia.org/wikipedia/commons/3/36/PhilHarveyNewYork17062021.png"
},
{
"image": "pat-smear.jpg",
"license": "GNU v.1.2",
"creator": "Andrew Burns",
"url": "https://upload.wikimedia.org/wikipedia/commons/6/66/Patsmear.jpg"
},
{
"image": "mike-kerr.jpg",
"license": "CC BY 4.0",
"creator": "Dena Flows",
"url": "https://upload.wikimedia.org/wikipedia/commons/8/85/017-BIME-2017-Royal-Blood-27X17-por-Dena-Flows.jpg"
},
{
"image": "matthew-bellamy.jpg",
"license": "CC BY 3.0",
"creator": "Minerva97",
"url": "https://upload.wikimedia.org/wikipedia/commons/d/d0/2009_Matthew_Bellamy_%28cropped%29.jpg"
},
{
"image": "capitol-outside.jpg",
"license": "",
"creator": "AxelHH",
"url": "https://upload.wikimedia.org/wikipedia/commons/6/6c/Hannover_Capitol_ganz.jpg"
},
{
"image": "red-hot-chili-peppers-logo.png",
"license": "",
"creator": "Viiticus",
"url": "https://upload.wikimedia.org/wikipedia/commons/3/31/Red_Hot_Chili_Peppers_logo.svg"
},
{
"image": "red-hot-chili-peppers-2.jpg",
"license": "CC BY-SA 4.0",
"creator": "Roberto Gianardi",
"url": "https://upload.wikimedia.org/wikipedia/commons/6/64/Red_Hot_Chili_Peppers_Bologna_2016.jpg"
},
{
"image": "arctic-monkeys-1.jpg",
"license": "CC BY 3.0",
"creator": "Bill Ebbesen",
"url": "https://upload.wikimedia.org/wikipedia/commons/0/04/Arctic_Monkeys_-_Orange_Stage_-_Roskilde_Festival_2014.jpg"
},
{
"image": ".jpg",
"license": "CC BY-SA 2.0",
"creator": "",
"url": ""
},
{
"image": "arctic-monkeys-3.jpg",
"license": "CC BY-SA 2.0",
"creator": "Aurelien Guichard",
"url": "https://upload.wikimedia.org/wikipedia/commons/f/f8/Arctic_Monkeys_%40_Shepherds_Bush_Empire.jpg"
},
{
"image": "european-tour-arctic-monkeys.jpg",
"license": "Gemeinfrei",
"creator": "Matthew Cooper",
"url": "https://upload.wikimedia.org/wikipedia/commons/e/e7/%22AM%22_%28Arctic_Monkeys%29.jpg"
},
{
"image": ".jpg",
"license": "CC BY-SA 2.0",
"creator": "",
"url": ""
}
]

Binary file not shown.

Before

Width:  |  Height:  |  Size: 55 KiB

After

Width:  |  Height:  |  Size: 539 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 67 KiB

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 101 KiB

After

Width:  |  Height:  |  Size: 953 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 3.9 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 155 KiB

After

Width:  |  Height:  |  Size: 6.0 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 MiB

After

Width:  |  Height:  |  Size: 193 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 426 KiB

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 143 KiB

After

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 356 KiB

After

Width:  |  Height:  |  Size: 5.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 150 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 447 KiB

After

Width:  |  Height:  |  Size: 2.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 648 KiB

After

Width:  |  Height:  |  Size: 339 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 197 KiB

After

Width:  |  Height:  |  Size: 111 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 126 KiB

After

Width:  |  Height:  |  Size: 276 KiB

View File

@@ -1,7 +1,8 @@
import { Request, Response, NextFunction, Router } from 'express'
import fs from "fs"
import fs, { createReadStream } from "fs"
import multer from "multer"
const upload = multer({ dest: './backend/images/' })
import licenses from "../data/licenses.json"
export const files = Router()
@@ -32,17 +33,20 @@ files.get("/:folder", async (req: Request, res: Response) => {
let result = []
let fileNames = fs.readdirSync("./backend/images/" + req.params.folder + "/")
fileNames.forEach(file => {
let resData = fs.readFileSync("./backend/images/" + req.params.folder + "/" + file, "utf8")
let resData = ""
let url = "http://localhost:3000/static/" + req.params.folder + "/" + file
if (file.endsWith("html") || file.endsWith("js")) {
resData = fs.readFileSync("./backend/images/" + req.params.folder + "/" + file, "utf8")
}
// todo License, Author, URL
result.push({
name: file,
size: fs.statSync("./backend/images/" + req.params.folder + "/" + file).size,
content: resData,
url: "http://localhost:3000/static/" + req.params.folder + "/" + file,
url: url,
copyright: licenses.find(data => data.image == file)
})
})

View File

@@ -29,6 +29,7 @@ startDatabase()
const path = require('path')
app.use('/static', express.static(path.join(__dirname, 'images')))
app.use("/exercises", exercises)
app.use("/files", files)
// Add delay for more realistic response times
app.use((req, res, next) => {
@@ -44,7 +45,6 @@ app.use("/orders", order)
app.use("/accounts", account)
app.use("/cities", city)
app.use("/concerts", concert)
app.use("/files", files)
// Start server
const server = app.listen(port, () => {