ipfs storage for images and other nontext items. for use with etica - runs on etica network and currencys
https://collect.etica-stats.org
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.5 KiB
37 lines
1.5 KiB
// /home/def/IPFSapp/backend/routes/delete-file.js |
|
// Marks a file "cancelled" (does not unpin from IPFS) |
|
|
|
export default function registerDeleteFile(app, _opts = {}) { |
|
app.post('/api/files/delete', async (req, res) => { |
|
try { |
|
const { query } = await import('pg'); |
|
} catch {} |
|
|
|
const poolMod = await import('pg'); |
|
const pool = new poolMod.Pool({ connectionString: process.env.DATABASE_URL }); |
|
const sql = (q, p = []) => pool.query(q, p); |
|
|
|
const b = req.body || {}; |
|
const byQuote = Number.isFinite(Number(b.quoteId)) ? Number(b.quoteId) : null; |
|
const byCid = (b.cid || '').toString() || null; |
|
|
|
let r; |
|
if (byQuote) { |
|
r = await sql(`UPDATE payments SET status='cancelled' WHERE quote_id=$1 RETURNING quote_id`, [byQuote]); |
|
} else if (byCid) { |
|
r = await sql(`UPDATE payments SET status='cancelled' WHERE cid=$1 RETURNING quote_id`, [byCid]); |
|
} else if (b.address && b.filename && b.createdAt) { |
|
r = await sql( |
|
`UPDATE payments SET status='cancelled' |
|
WHERE lower(address)=lower($1) AND filename=$2 AND created_at=$3 |
|
RETURNING quote_id`, |
|
[b.address, b.filename, b.createdAt] |
|
); |
|
} else { |
|
return res.status(400).json({ ok: false, error: 'selector required (quoteId or cid or address+filename+createdAt)' }); |
|
} |
|
|
|
if (r.rowCount === 0) return res.status(404).json({ ok: false, error: 'not found' }); |
|
res.json({ ok: true, deleted: r.rows[0].quote_id }); |
|
}); |
|
}
|
|
|