Introduce prettier

This commit is contained in:
Takeshi Kimata
2024-05-19 21:04:45 +09:00
parent cbb5993276
commit 75eeebefda
89 changed files with 872 additions and 944 deletions

View File

@@ -1,32 +1,32 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const path = require("path");
const fs = require("fs");
const defineAttachment = require("../../models/attachments");
const { DataTypes } = require("sequelize");
const path = require('path');
const fs = require('fs');
const defineAttachment = require('../../models/attachments');
const { DataTypes } = require('sequelize');
module.exports = function (sequelize) {
const Attachment = defineAttachment(sequelize, DataTypes);
router.get("/download/:attachmentId", async (req, res) => {
router.get('/download/:attachmentId', async (req, res) => {
const attachmentId = req.params.attachmentId;
try {
const attachment = await Attachment.findByPk(attachmentId);
if (!attachment) {
return res.status(404).send("Attachment not found");
return res.status(404).send('Attachment not found');
}
const filename = attachment.path.split("/").pop();
const filename = attachment.path.split('/').pop();
const filePath = path.join(__dirname, `../../public/uploads/${filename}`);
if (!fs.existsSync(filePath)) {
return res.status(404).json({ error: "File not found" });
return res.status(404).json({ error: 'File not found' });
}
res.download(filePath);
} catch (error) {
console.error(error);
res.status(500).send("Internal Server Error");
res.status(500).send('Internal Server Error');
}
});