Skip to content

Instantly share code, notes, and snippets.

@anggoran
Created January 13, 2023 04:05
Show Gist options
  • Save anggoran/ede27a14c82a8c1effa3eed56faf4f6b to your computer and use it in GitHub Desktop.
Save anggoran/ede27a14c82a8c1effa3eed56faf4f6b to your computer and use it in GitHub Desktop.
Generating Sparkle Feed using Deno
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.2.3";
import js2xmlparser from "https://esm.sh/js2xmlparser@5.0.0";
serve(async () => {
const supabaseURL = Deno.env.get("SUPABASE_URL");
const supabaseAnon = Deno.env.get("SUPABASE_ANON_KEY");
const supabase = createClient(supabaseURL!, supabaseAnon!);
const { data } = await supabase.from("apps").select();
const applications = [];
for (const app of data!) {
if (app["macos_url"] !== null) {
applications.push({
title: "Version" + " " + app["version"],
pubDate: app["created_at"],
enclosure: {
"@": {
"sparkle:os": "macos",
"sparkle:version": app["version"] as string,
type: "application/octet-stream",
url: app["macos_url"] as string,
"sparkle:edSignature": app["macos_signature"] as string,
},
},
});
}
if (app["windows_url"] !== null) {
applications.push({
title: "Version" + " " + app["version"],
pubDate: app["created_at"],
enclosure: {
"@": {
"sparkle:os": "windows",
"sparkle:version": app["version"] as string,
type: "application/octet-stream",
url: app["windows_url"] as string,
"sparkle:dsaSignature": app["windows_signature"] as string,
},
},
});
}
}
const feed = {
"@": {
version: "2.0",
"xmlns:sparkle": "http://www.andymatuschak.org/xml-namespaces/sparkle",
},
"#": {
channel: {
title: "Appname RSS",
description: "Auto Updates for Appname App",
language: "en",
item: applications,
},
},
};
const rssFEED = js2xmlparser.parse("rss", feed, {
declaration: { encoding: "UTF-8" },
});
return new Response(rssFEED, {
headers: { "Content-Type": "application/xml" },
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment