Fix issue #35: Dragonroll frontend: item modifications
All checks were successful
Test / test (push) Successful in 2s

This commit is contained in:
Gitea OpenCode Agent
2026-10-14 18:08:19 +00:00
parent 2c78ad039a
commit 22c6403736
15 changed files with 404 additions and 20 deletions

View File

@@ -1,6 +1,8 @@
const express = require('express');
const router = express.Router();
const upload = require('../services/storage');
const Campaign = require('../models/Campaign');
const Item = require('../models/Item');
@@ -44,7 +46,7 @@ router.post('/create', async (req, res) => {
router.post('/update', async (req, res) => {
try {
const { id, name, category, rarity, quantity, weight, properties, description } = req.body;
const { id, name, category, rarity, quantity, weight, properties, description, image } = req.body;
if (!id) return res.json({ status: 'error', msg: 'errors.missing-data' });
const item = await Item.findById(id);
@@ -58,6 +60,7 @@ router.post('/update', async (req, res) => {
if (weight !== undefined && weight !== '') item.weight = Number(weight);
if (properties !== undefined) item.properties = properties;
if (description !== undefined) item.description = description;
if (image !== undefined) item.image = String(image);
await item.save();
res.json({ status: 'ok', item });
@@ -67,6 +70,25 @@ router.post('/update', async (req, res) => {
}
});
// Upload item image post
router.post("/upload-image", upload.single("image"), async (req, res) => {
try {
const itemId = req.query.item || req.body.item;
if (!itemId || !req.file) return res.json({ status: 'error', msg: 'errors.missing-data' });
const item = await Item.findById(itemId);
if (!item) return res.json({ status: 'error', msg: 'errors.notfound' });
if (!(await userOwnsCampaign(item.campaign, req.user.id))) return res.json({ status: 'error', msg: 'unauthorized' });
item.image = req.file.filename;
await item.save();
res.json({ status: "ok", msg: "uploaded", item });
} catch (err) {
console.error(err);
res.json({ status: "error", msg: "internal" });
}
});
router.post('/delete', async (req, res) => {
try {
const { id } = req.body;