Browse Source

add claim_type and handle_id to record

pull/1/head
Trent Larson 9 months ago
parent
commit
0310742988
  1. 2
      README.md
  2. 9
      server.js
  3. 2
      sql/migrations/V1__Create_image_table.sql

2
README.md

@ -26,6 +26,8 @@ AWS_REGION=
INFURA_PROJECT_ID=
```
If you use a domain with a web redirect, use a permanent redirect (since browsers complained with PR_END_OF_FILE_ERROR about a secure connection when it's temporary).
## dev
```

9
server.js

@ -175,12 +175,16 @@ app.post('/image', uploadMulter.single('image'), async (req, res) => {
const currentDate = new Date().toISOString();
const localFile = reqFile.path.startsWith(uploadDir + '/') ? reqFile.path.substring(uploadDir.length + 1) : reqFile.path;
const finalUrl = `https://${imageServer}/${fileName}`;
const claimType = req.body.claimType;
const handleId = req.body.handleId;
await new Promise((resolve, reject) => {
db.run(
'INSERT INTO image (time, did, local_file, size, final_file, url) VALUES (?, ?, ?, ?, ?, ?)',
'INSERT INTO image (time, did, claim_type, handle_id, local_file, size, final_file, url) VALUES (?, ?, ?, ?, ?, ?, ?, ?)',
[
currentDate,
issuerDid,
claimType,
handleId,
localFile,
reqFile.size,
fileName,
@ -272,6 +276,7 @@ app.delete('/image/:url', async (req, res) => {
);
});
if (!thisUserImageFile) {
console.log('No image entry found for user', issuerDid, '& URL', url, 'so returning 404.');
return res.status(404).send(JSON.stringify({ success: false, message: 'No image entry found for user ' + issuerDid + ' & URL ' + url }));
}
@ -282,7 +287,7 @@ app.delete('/image/:url', async (req, res) => {
[ url, issuerDid ],
(dbErr, row) => {
if (dbErr) {
console.error(currentDate, 'Error getting image for user from database:', dbErr)
console.error(currentDate, 'Error getting image for other users from database:', dbErr)
reject(dbErr);
}
resolve(row?.did);

2
sql/migrations/V1__Create_image_table.sql

@ -2,6 +2,8 @@
CREATE TABLE image (
time TEXT NOT NULL, -- ISO 8601 @ UTC, eg 2019-01-01T00:00:00Z
did TEXT NOT NULL,
claim_type TEXT,
handle_id TEXT,
local_file TEXT NOT NULL,
size INTEGER NOT NULL,
final_file TEXT NOT NULL,

Loading…
Cancel
Save