Skip to content

Commit

Permalink
Add "dev ring" generator
Browse files Browse the repository at this point in the history
  • Loading branch information
CorySanin committed Mar 5, 2021
1 parent bff664e commit 355ec35
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ FROM node:alpine3.12

WORKDIR /usr/src/p-to-z

copy package*.json ./
COPY package*.json ./

ENV NPM_CONFIG_LOGLEVEL warn
RUN npm ci --only=production

copy . .
COPY . .

CMD [ "npm", "start" ]
32 changes: 29 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const useragent = 'p2z';
const cfgfile = './config/config.json';
const LEADINGAMP = new RegExp('(https?://[^\\s]+\\?)&amp;([^<"\\s]+)', 'g');
const MATCHURL = new RegExp(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:;%_\+.~#?&//=]*)/, 'g');
const MATCHHEX = new RegExp('^[0-9a-fA-F]{1,3}$');
const MATCHBIN = new RegExp('^[01]{1,12}$');
const proxy = httpProxy.createProxyServer({
secure: false,
changeOrigin: true,
Expand Down Expand Up @@ -136,8 +138,8 @@ function logDomain(domain) {
* @param {string} useragent
*/
function nonsupported(useragent) {
for(var i = 0; i < unsupportedAgents.length; i++){
if(useragent.os.includes(unsupportedAgents[i])){
for (var i = 0; i < unsupportedAgents.length; i++) {
if (useragent.os.includes(unsupportedAgents[i])) {
return true;
}
}
Expand All @@ -157,6 +159,30 @@ http.get('/', function (req, res) {
});
});

http.get('/ring/:id', function (req, res) {
let id = -1;
if (MATCHHEX.test(req.params['id'])) {
id = parseInt(req.params['id'], 16);
}
else if (MATCHBIN.test(req.params['id'])) {
id = parseInt(req.params['id'], 2);
}
if(id >= 0){
let rings = [];
for(let i = 0; i < 12; i++){
rings.push((id >> i) & 1);
}
res.set('Content-Type', 'image/svg+xml');
res.render('dev-ring', {
rings
});
}
else{
res.status(403);
res.send();
}
});

http.get('/feed/out.xml', async function (req, res) {
let url = req.query.in;
if (!/^[a-z]+:\/\//.test(url.toLowerCase())) {
Expand All @@ -177,7 +203,7 @@ http.get('/feed/out.xml', async function (req, res) {
if (resp.statusCode) {
res.status(resp.statusCode);
}
res.setHeader('Content-Type', 'text/xml;charset=UTF-8');
res.set('Content-Type', 'text/xml;charset=UTF-8');
let body = null;
try {
body = proxifyUrls(fixUrls(resp.body.toString()), `${req.protocol}://${req.headers.host}`);
Expand Down
30 changes: 30 additions & 0 deletions views/dev-ring.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 587.089 586.399">
<path id="logo" d="M437.947,223.648c4.347-7.67,8.435-16.872-5.366-24.794s-110.163-64.415-123.457-72.589l-.511.254c-6.137-3.069-18.661-8.952-30.414-1.282S176.723,185.56,160.62,195.019,149.372,217,157.551,221.857s30.931,18.661,38.087,23.511,13.544,10.737,7.411,21.22-46.007,80-54.186,93.294-4.087,24.024,5.881,30.159,106.587,61.854,118.088,68.5,22.744,9.2,33.737,3.316,109.655-64.15,121.923-71.567,6.389-19.679,1.02-23-32.718-21.212-43.2-27.856-9.455-11-3.835-20.961C387.889,308.883,433.6,231.315,437.947,223.648ZM205.122,234.577c-5.072-2.71-23.764-13.639-28.53-16.6-8.943-5.56-6.11-14.15.048-17.282s69.207-39.157,76.633-42.588c6.279-2.9,12.34,2.207,7.99,10.182-2.747,5.043-30.776,52.482-35.893,61.176S213.437,239.012,205.122,234.577ZM179.943,336.422c2.687-5.078,30.123-52.863,35.128-61.618s11.817-9.7,20.19-5.37c5.1,2.652,23.929,13.352,28.728,16.258,9.012,5.448,6.286,14.067.172,17.279s-68.721,40.008-76.1,43.53C181.815,349.484,175.7,344.445,179.943,336.422ZM285.312,432.9c-.544,9.2-7.822,13.455-21.058,5.51s-79.63-45.53-87.949-50.13-12.713-12.109-1.33-18.471,83.125-47.729,93.368-54.013,17.582-3.185,17.468,9.619C285.67,342.377,285.852,423.7,285.312,432.9Zm.462-168.078c.262,6.9-5.862,13.553-15.069,8.452-4.912-2.722-23.563-13.73-28.389-16.837-7.932-5.1-10.5-11.492-5.394-20.185s32.9-56.276,35.963-61.132c4.849-7.674,12.266-4.876,12.787,2.025.612,8.155-.161,80.775.1,87.677Zm14.4-108.653c-.256-12.009,6.129-16.783,17.122-10.224,14.57,8.695,84.855,49.588,92.525,54.7s7.667,13.548-5.879,20.959-79.493,45.753-87.667,50.61-16.872,4.859-16.616-8.181S300.434,168.177,300.177,156.166Zm0,254.578c-.606-8.158.254-80.772,0-87.672s5.878-13.546,15.081-8.437c4.9,2.726,23.543,13.757,28.37,16.872,7.92,5.113,10.477,11.5,5.37,20.194s-32.967,56.236-36.042,61.087C308.1,420.457,300.691,417.644,300.177,410.744Zm80.616-57.328c5.066,2.711,23.748,13.668,28.5,16.64,8.94,5.572,6.1,14.158-.064,17.282S339.97,426.4,332.545,429.829c-6.284,2.894-12.34-2.225-7.984-10.193,2.753-5.043,30.838-52.443,35.963-61.132s11.959-9.539,20.272-5.088Zm-9.9-40.247c-5.016,8.747-11.833,9.692-20.2,5.344-5.095-2.658-23.911-13.376-28.712-16.288-9-5.457-6.267-14.078-.147-17.276s68.773-39.928,76.153-43.447c6.247-2.97,12.367,2.073,8.112,10.092-2.693,5.076-30.184,52.827-35.2,61.575Z" transform="translate(-0.448 -0.666)"/>
<g fill="none" stroke="#000">
<% if (rings[0]) { %>
<path d="M312.42,75.243c104.254,5.836,194.254,96.836,200.15,201.021" transform="translate(-0.448 -0.666)" stroke-linecap="round" stroke-miterlimit="10" stroke-width="11"/>
<% } if (rings[1]) { %>
<path d="M75.372,274.245c6.3-103.166,96.3-194.166,199.823-198.96" transform="translate(-0.448 -0.666)" stroke-linecap="round" stroke-miterlimit="10" stroke-width="11"/>
<% } if (rings[2]) { %>
<path d="M275.172,512.488c-21.342-.616-42.975-5.88-62.862-13.448a209.6,209.6,0,0,1-50.418-27.284c-15.948-11.83-29.512-26.106-41.407-41.96A244.3,244.3,0,0,1,90.51,378.155,196.453,196.453,0,0,1,75.8,320.907q-.36-3.739-.564-7.491" transform="translate(-0.448 -0.666)" stroke-linecap="round" stroke-miterlimit="10" stroke-width="11"/>
<% } if (rings[3]) { %>
<path d="M512.517,312.794c-5.843,104.285-95.843,195.285-199.872,199.566" transform="translate(-0.448 -0.666)" stroke-linecap="round" stroke-miterlimit="10" stroke-width="11"/>
<% } if (rings[4]) { %>
<path d="M312.739,40.764c121.935,3.315,229.935,112.315,234.722,234.221" transform="translate(-0.448 -0.666)" stroke-linecap="round" stroke-miterlimit="10" stroke-width="11"/>
<% } if (rings[5]) { %>
<path d="M40.989,275.146C44.3,153.212,153.3,45.212,275.211,40.424" transform="translate(-0.448 -0.666)" stroke-linecap="round" stroke-miterlimit="10" stroke-width="11"/>
<% } if (rings[6]) { %>
<path d="M275.114,547.265a223.91,223.91,0,0,1-71.441-14.477,248.273,248.273,0,0,1-60.61-33.374A262.969,262.969,0,0,1,94.129,451.79a255.071,255.071,0,0,1-35.22-59.5A230.9,230.9,0,0,1,41.62,322.524q-.391-4.7-.581-9.406" transform="translate(-0.448 -0.666)" stroke-linecap="round" stroke-miterlimit="10" stroke-width="11"/>
<% } if (rings[7]) { %>
<path d="M547.339,313.8c-1.665,37.275-12.665,72.275-30.665,105.275l-9,15c-29,42-64,73-109,93-27,11-56,20-85.873,19.471" transform="translate(-0.448 -0.666)" stroke-linecap="round" stroke-miterlimit="10" stroke-width="11"/>
<% } if (rings[8]) { %>
<path d="M312.986,6.168c58.688,2.911,113.688,23.911,160.688,61.911,4,4,8,7,13,11,33,30,57,64,75,104,2,6,5,11,7,17,7,25,14,49,13.317,74.866" transform="translate(-0.448 -0.666)" stroke-linecap="round" stroke-miterlimit="10" stroke-width="11"/>
<% } if (rings[9]) { %>
<path d="M6.113,274.767c1.561-52.688,17.561-100.688,48.561-146.688,30-43,66-75,112-96,21-9,42-17,66-21,15-2,29-4,43.4-4.913" transform="translate(-0.448 -0.666)" stroke-linecap="round" stroke-miterlimit="10" stroke-width="11"/>
<% } if (rings[10]) { %>
<path d="M275.392,581.51a307.368,307.368,0,0,1-82.581-17.5,287.5,287.5,0,0,1-70.922-37.548,283.361,283.361,0,0,1-56.142-54.273A279.44,279.44,0,0,1,26.34,404.428,291.078,291.078,0,0,1,6.781,323.647q-.507-5.248-.833-10.512" transform="translate(-0.448 -0.666)" stroke-linecap="round" stroke-miterlimit="10" stroke-width="11"/>
<% } if (rings[11]) { %>
<path d="M581.808,312.6c-.134,23.482-5.134,46.482-12.134,68.482-3,7-5,15-8,22-23,53-56,98-106,132l-15,9c-40,22-83,36-127.714,37.486" transform="translate(-0.448 -0.666)" stroke-linecap="round" stroke-miterlimit="10" stroke-width="11"/>
<% } %>
</g>
</svg>
13 changes: 7 additions & 6 deletions views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<head>
<meta charset="UTF-8">
<title>Patreon to Zune | Import Patreon Podcasts to the Zune Software</title>
<meta name="description" content="Proxy that allows importing Patreon podcasts into the Zune desktop software" />
<meta name="description" content="Proxy that allows importing Patreon podcasts into the Zune desktop software." />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" type="image/png" href="/assets/favicon.png" sizes="32x32">
<link rel="stylesheet" href="/styles/reset.css">
Expand All @@ -16,17 +16,18 @@
<div id="brandtag"></div>
<div>
<div id="nav">
<h1><a class="current" href="/">Patreon to Zune</a></h1>
<h1><a class="current" href="/">Patreon&nbsp;to&nbsp;Zune</a></h1>
<% if (config.deepproxyurl) { %>
<a href="<%= config.deepproxyurl %>">Content Proxy</a>
<a href="<%= config.deepproxyurl %>">Content&nbsp;Proxy</a>
<% } %>
<a href="https://github.com/CorySanin/patreon-to-zune">Fork on GitHub</a>
<a href="https://github.com/CorySanin/patreon-to-zune/issues/new">Report Issue</a>
<a href="/ring/EA7">Ring&nbsp;Generator</a>
<a href="https://github.com/CorySanin/patreon-to-zune">Fork&nbsp;on&nbsp;GitHub</a>
<a href="https://github.com/CorySanin/patreon-to-zune/issues/new">Report&nbsp;Issue</a>
</div>
<% if (config.deepproxyurl && nonsupported) { %>
<span class="tooltip panel">
<div class="brandtag-horiz"></div>Looks like you're using an old OS. If you're still getting error code
C00D1335, try the <a href="<%= config.deepproxyurl %>">content proxy</a>.
C00D1335 or C00D1337, try the <a href="<%= config.deepproxyurl %>">content proxy</a>.
</span>
<% } %>
</div>
Expand Down

0 comments on commit 355ec35

Please sign in to comment.