INNER CODE UNIT · JavaScript

calculateFileHash

ruwiss/ai-auto-free · ai-auto-free/backend/index.js:69

async function calculateFileHash(filePath) {
  try {
    const fileContent = await fsPromises.readFile(filePath);
    return crypto.createHash("sha256").update(fileContent).digest("hex");
  } catch (error) {
    throw new Error("Error calculating file hash");
  }
}

// Dosyanın hash'ini döndüren endpoint
app.get("/api/hash/:filename", async (req, res) => {
  try {
    const filename = req.params.filename;
    const filePath = path.join(__dirname, "codes", filename);

    const hash = await calculateFileHash(filePath);
    res.json({ hash });
  } catch (error) {

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…