Skip to content

Commit

Permalink
add server endpoints to handle goteo api calls
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbeig committed Jun 14, 2023
1 parent a29fa96 commit d4daee0
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion server/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { RegisterServerOptions } from '@peertube/peertube-types'

async function register ({ registerSetting }: RegisterServerOptions): Promise<void> {
async function register ({ registerSetting, getRouter, settingsManager }: RegisterServerOptions): Promise<void> {
registerSetting({
name: 'goteo-url',
label: 'Goteo URL',
Expand All @@ -24,6 +24,39 @@ async function register ({ registerSetting }: RegisterServerOptions): Promise<vo
private: true,
default: ''
})

const router = getRouter()
router.get('/login', async (req, res) => {

const username = await settingsManager.getSetting('goteo-api-user')
const apikey = await settingsManager.getSetting('goteo-api-key')

const fetch = require('node-fetch')
const response = await fetch('https://api.goteo.org/v1/login', {
headers: {
'Authorization': 'Basic ' + btoa(username + ":" + apikey)
}
}).json()

res.send(response)
})

router.get('/goteo/project/:id/rewards', async (req, res) => {
const username = await settingsManager.getSetting('goteo-api-user')
const apikey = await settingsManager.getSetting('goteo-api-key')

const project = req.params.id

const fetch = require('node-fetch')
const response = await fetch('https://api.goteo.org/v1/projects/' + project, {
headers: {
'Authorization': 'Basic ' + btoa(username + ":" + apikey)
}
})

const data = await response.json()
res.send(data.rewards)
})
}

async function unregister (): Promise<void> {}
Expand Down

0 comments on commit d4daee0

Please sign in to comment.