This commit is contained in:
@@ -57,12 +57,11 @@ export function getRouteGpxFile(db, id) {
|
||||
|
||||
export function createRoute(db, fields, gpxFile) {
|
||||
if (!gpxFile) throw new HttpError(400, 'Eine GPX-Datei ist erforderlich.');
|
||||
const parsed = parseGpx(fs.readFileSync(gpxFile.path, 'utf8'));
|
||||
const name = String(fields.name || parsed.name || '').trim();
|
||||
if (!name) throw new HttpError(400, 'Ein Streckenname ist erforderlich.');
|
||||
let routeId;
|
||||
let finalGpx;
|
||||
try {
|
||||
const parsed = parseGpx(fs.readFileSync(gpxFile.path, 'utf8'));
|
||||
const name = String(fields.name || parsed.name || '').trim();
|
||||
if (!name) throw new HttpError(400, 'Ein Streckenname ist erforderlich.');
|
||||
routeId = transaction(db, () => {
|
||||
let slug = slugify(fields.slug || name);
|
||||
let suffix = 2;
|
||||
@@ -79,7 +78,7 @@ export function createRoute(db, fields, gpxFile) {
|
||||
return id;
|
||||
});
|
||||
ensureRouteDirectories(routeId);
|
||||
finalGpx = path.join(routeDirectory(routeId), 'route.gpx');
|
||||
const finalGpx = path.join(routeDirectory(routeId), 'route.gpx');
|
||||
const gpxPath = moveUploadedFile(gpxFile, finalGpx);
|
||||
db.prepare("UPDATE routes SET gpx_path = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?").run(gpxPath, routeId);
|
||||
return getRoute(db, routeId);
|
||||
|
||||
Reference in New Issue
Block a user