Skip to content

Commit f9fb131

Browse files
committed
2 parents 4b29386 + ccadd92 commit f9fb131

4 files changed

Lines changed: 19 additions & 7 deletions

File tree

.github/workflows/live.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
jobs:
77
build:
88
runs-on: ubuntu-latest
9+
permissions:
10+
packages: write
11+
contents: read
912

1013
steps:
1114
- name: Check out the repo

.github/workflows/stage.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ on:
99
jobs:
1010
build:
1111
runs-on: ubuntu-latest
12+
permissions:
13+
packages: write
14+
contents: read
1215

1316
steps:
1417
- name: Check out the repo

src/OnionooService.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ export class OnionooService {
1313
}
1414

1515
async updateHardwareInfo(hardwareInfo: HardwareInfo): Promise<any> {
16-
const finferprint = hardwareInfo.fingerprint;
17-
const response = await axios.put(`${this.baseUrl}/hardware/${finferprint}`, hardwareInfo).then();
16+
const fingerprint = hardwareInfo.fingerprint;
17+
if (fingerprint.length !== 40) { throw new Error('Fingerprint must be 40 char hex string') }
18+
const response = await axios.put(`${this.baseUrl}/hardware/${encodeURIComponent(fingerprint)}`, hardwareInfo).then();
1819
return response.data;
1920
}
2021
}

src/app.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,9 @@ const hardware_relay_validation_rules = [
219219
body('company').notEmpty().withMessage("company should not be empty"),
220220
body('format').notEmpty().withMessage("format should not be empty"),
221221
body('wallet').notEmpty().withMessage("wallet should not be empty"),
222-
body('fingerprint').notEmpty().withMessage("fingerprint should not be empty"),
222+
body('fingerprint')
223+
.notEmpty().withMessage("fingerprint should not be empty")
224+
.matches(/^[a-fA-F0-9]{40}$/).withMessage("fingerprint must be a 40 character hexadecimal string"),
223225
body('nftid').notEmpty().withMessage("nftid should not be empty"),
224226
body('build').notEmpty().withMessage("build should not be empty"),
225227
body('flags').notEmpty().withMessage("flags should not be empty"),
@@ -242,10 +244,13 @@ app.post('/hardware', hardware_relay_validation_rules, async (req: any, res: any
242244
if (!errors.isEmpty()) {
243245
return res.status(400).json({ errors: errors.array() });
244246
}
245-
246-
const updateHardwareInfo = await onionooService.updateHardwareInfo(hardwareInfo);
247-
248-
res.status(200).send(updateHardwareInfo);
247+
try {
248+
const updateHardwareInfo = await onionooService.updateHardwareInfo(hardwareInfo);
249+
return res.status(200).send(updateHardwareInfo);
250+
} catch (error) {
251+
console.error(error);
252+
return res.status(500).send('Error posting hardware info');
253+
}
249254
});
250255

251256
function buildQuery(metric: string): string {

0 commit comments

Comments
 (0)