Skip to content
This repository was archived by the owner on Mar 2, 2021. It is now read-only.

Commit 7c5d13b

Browse files
authored
Add /backup endpoint for exporting a radio (#39)
* Add /backup endpoint for exporting a radio * Upgrade radio4000-sdk for the backup method
1 parent 2e2ce0c commit 7c5d13b

File tree

5 files changed

+51
-2
lines changed

5 files changed

+51
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ These come from the node.js app in this repo.
5757
|--------|-------|
5858
|https://api.radio4000.com/embed?slug={channelSlug}|Returns an HTML embed with the [radio4000-player](https://github.com/internet4000/radio4000-player)|
5959
|https://api.radio4000.com/oembed?slug={channelSlug}|Returns a `JSON` object following the [oEmbed spec](http://oembed.com/) for a Radio4000 channel. With this, we can add a meta tag to each channel to get rich previews when the link is shared.|
60+
|https://api.radio4000.com/backup?slug={channelSlug}|Returns a full JSON export of a channel|
6061

6162
The `/embed` endpoint is meant to be used as the `src` of our `<iframe>` embeds. To get the HTML for the iframe embed, visit the `/oembed` endpoint and see the `html` property.
6263

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"firebase-admin": "^5.10.0",
2020
"firebase-functions": "^0.8.2",
2121
"got": "^6.7.1",
22+
"radio4000-sdk": "^0.0.5",
2223
"stripe": "^4.24.0"
2324
},
2425
"devDependencies": {

src/app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const config = require('./config')
77
const billings = require('./billings')
88
const embed = require('./embed')
99
const oembed = require('./oembed')
10+
const backup = require('./backup')
1011

1112
/* Start Express server */
1213
const app = express()
@@ -24,5 +25,6 @@ app.get('/', function (req, res) {
2425
app.use('/billings', billings)
2526
app.use('/embed', embed)
2627
app.use('/oembed', oembed)
28+
app.use('/backup', backup)
2729

2830
module.exports = app

src/backup/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const express = require('express')
2+
const noEndpoint = require('../utils/no-endpoint')
3+
const {createBackup} = require('radio4000-sdk')
4+
5+
const route = express.Router()
6+
7+
module.exports = route.get('/', (req, res) => {
8+
const slug = req.query.slug
9+
10+
if (!slug) return noEndpoint(res)
11+
12+
createBackup(slug)
13+
.then(backup => res.send(backup))
14+
})
15+

yarn.lock

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,6 +1964,12 @@ encodeurl@~1.0.1:
19641964
version "1.0.1"
19651965
resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.1.tgz#79e3d58655346909fe6f0f45a5de68103b294d20"
19661966

1967+
encoding@^0.1.11:
1968+
version "0.1.12"
1969+
resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.12.tgz#538b66f3ee62cd1ab51ec323829d1f9480c74beb"
1970+
dependencies:
1971+
iconv-lite "~0.4.13"
1972+
19671973
end-of-stream@^1.0.0, end-of-stream@^1.1.0:
19681974
version "1.4.0"
19691975
resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.0.tgz#7a90d833efda6cfa6eac0f4949dbb0fad3a63206"
@@ -3147,7 +3153,7 @@ i@0.3.x:
31473153
version "0.3.6"
31483154
resolved "https://registry.yarnpkg.com/i/-/i-0.3.6.tgz#d96c92732076f072711b6b10fd7d4f65ad8ee23d"
31493155

3150-
iconv-lite@0.4.19:
3156+
iconv-lite@0.4.19, iconv-lite@~0.4.13:
31513157
version "0.4.19"
31523158
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.19.tgz#f7468f60135f5e5dad3399c0a81be9a1603a082b"
31533159

@@ -3482,7 +3488,7 @@ is-stream-ended@^0.1.0:
34823488
version "0.1.3"
34833489
resolved "https://registry.yarnpkg.com/is-stream-ended/-/is-stream-ended-0.1.3.tgz#a0473b267c756635486beedc7e3344e549d152ac"
34843490

3485-
is-stream@^1.0.0, is-stream@^1.1.0:
3491+
is-stream@^1.0.0, is-stream@^1.0.1, is-stream@^1.1.0:
34863492
version "1.1.0"
34873493
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"
34883494

@@ -3540,6 +3546,13 @@ isobject@^3.0.0, isobject@^3.0.1:
35403546
version "3.0.1"
35413547
resolved "https://registry.yarnpkg.com/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df"
35423548

3549+
isomorphic-unfetch@^2.0.0:
3550+
version "2.0.0"
3551+
resolved "https://registry.yarnpkg.com/isomorphic-unfetch/-/isomorphic-unfetch-2.0.0.tgz#f50140a4c163d7582b5f37f1591968c4f809a645"
3552+
dependencies:
3553+
node-fetch "^1.7.1"
3554+
unfetch "^3.0.0"
3555+
35433556
isstream@0.1.x, isstream@~0.1.2:
35443557
version "0.1.2"
35453558
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
@@ -4261,6 +4274,13 @@ next-tick@1:
42614274
version "1.0.0"
42624275
resolved "https://registry.yarnpkg.com/next-tick/-/next-tick-1.0.0.tgz#ca86d1fe8828169b0120208e3dc8424b9db8342c"
42634276

4277+
node-fetch@^1.7.1:
4278+
version "1.7.3"
4279+
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef"
4280+
dependencies:
4281+
encoding "^0.1.11"
4282+
is-stream "^1.0.1"
4283+
42644284
node-forge@0.7.1:
42654285
version "0.7.1"
42664286
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.7.1.tgz#9da611ea08982f4b94206b3beb4cc9665f20c300"
@@ -4964,6 +4984,12 @@ query-string@^5.0.1:
49644984
object-assign "^4.1.0"
49654985
strict-uri-encode "^1.0.0"
49664986

4987+
radio4000-sdk@^0.0.5:
4988+
version "0.0.5"
4989+
resolved "https://registry.yarnpkg.com/radio4000-sdk/-/radio4000-sdk-0.0.5.tgz#8de7f33ebc451200501f6e88a8f36803d4b803f8"
4990+
dependencies:
4991+
isomorphic-unfetch "^2.0.0"
4992+
49674993
randomatic@^1.1.3:
49684994
version "1.1.7"
49694995
resolved "https://registry.yarnpkg.com/randomatic/-/randomatic-1.1.7.tgz#c7abe9cc8b87c0baa876b19fde83fd464797e38c"
@@ -6098,6 +6124,10 @@ underscore@1.x:
60986124
version "1.8.3"
60996125
resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.8.3.tgz#4f3fb53b106e6097fcf9cb4109f2a5e9bdfa5022"
61006126

6127+
unfetch@^3.0.0:
6128+
version "3.0.0"
6129+
resolved "https://registry.yarnpkg.com/unfetch/-/unfetch-3.0.0.tgz#8d1e0513a4ecd0e5ff2d41a6ba77771aae8b6482"
6130+
61016131
union-value@^1.0.0:
61026132
version "1.0.0"
61036133
resolved "https://registry.yarnpkg.com/union-value/-/union-value-1.0.0.tgz#5c71c34cb5bad5dcebe3ea0cd08207ba5aa1aea4"

0 commit comments

Comments
 (0)