From 3aeb97712f8e72beba8d2b6c2eb09002f834ab4a Mon Sep 17 00:00:00 2001 From: Pof Magicfingers Date: Mon, 9 Nov 2020 14:32:29 +0100 Subject: [PATCH] feat: adds social and platform links --- src/connectors/feed.js | 17 ++++++- .../resolvers/podcastForFeedWithIdentifier.js | 17 ++++++- src/schema/queries/resolvers/podcasts.js | 14 +++++- src/schema/types/platforms.js | 11 +++++ src/schema/types/podcast.js | 16 +++++- src/schema/types/resolvers/podcast.js | 49 ++++++++++++++++++- src/schema/types/socials.js | 13 +++++ src/utils/index.js | 6 ++- 8 files changed, 137 insertions(+), 6 deletions(-) create mode 100644 src/schema/types/platforms.js create mode 100644 src/schema/types/socials.js diff --git a/src/connectors/feed.js b/src/connectors/feed.js index 9e051b8e..621b27e3 100644 --- a/src/connectors/feed.js +++ b/src/connectors/feed.js @@ -31,7 +31,22 @@ const FeedSchema = new Mongoose.Schema({ itunes_category: String, disabled: Boolean, feed_redirect_url: String, - web_redirect_url: String + web_redirect_url: String, + itunes: String, + google_podcasts: String, + spotify: String, + deezer: String, + podcloud: String, + youtube: String, + soundcloud: String, + dailymotion: String, + twitch: String, + twitter: String, + facebook: String, + instagram: String, + wiki: String, + shop: String, + donate: String }) const Feed = Mongoose.model("feeds", FeedSchema) diff --git a/src/schema/queries/resolvers/podcastForFeedWithIdentifier.js b/src/schema/queries/resolvers/podcastForFeedWithIdentifier.js index d87e849e..6ccd7805 100644 --- a/src/schema/queries/resolvers/podcastForFeedWithIdentifier.js +++ b/src/schema/queries/resolvers/podcastForFeedWithIdentifier.js @@ -42,7 +42,22 @@ const PodcastFields = [ "ordering", "updated_at", "feed_cover", - "_slugs" + "_slugs", + "itunes", + "google_podcasts", + "spotify", + "deezer", + "podcloud", + "youtube", + "soundcloud", + "dailymotion", + "twitch", + "twitter", + "facebook", + "instagram", + "wiki", + "shop", + "donate" ] const podcastForFeedWithIdentifier = function(obj, args, context, info) { diff --git a/src/schema/queries/resolvers/podcasts.js b/src/schema/queries/resolvers/podcasts.js index 294eeb19..95153452 100644 --- a/src/schema/queries/resolvers/podcasts.js +++ b/src/schema/queries/resolvers/podcasts.js @@ -24,7 +24,19 @@ const PodcastFields = [ "ordering", "updated_at", "feed_cover", - "_slugs" + "_slugs", + "twitter", + "facebook", + "instagram", + "youtube", + "itunes", + "wiki", + "spotify", + "google_podcasts", + "deezer", + "soundcloud", + "shop", + "donate" ] const podcasts = function() { diff --git a/src/schema/types/platforms.js b/src/schema/types/platforms.js new file mode 100644 index 00000000..eee0ac14 --- /dev/null +++ b/src/schema/types/platforms.js @@ -0,0 +1,11 @@ +const Platforms = ` +type Platforms { + apple: String + google: String + spotify: String + deezer: String + podcloud: String +} +` + +export default () => [Platforms] diff --git a/src/schema/types/podcast.js b/src/schema/types/podcast.js index 4f3946e5..8ac13496 100644 --- a/src/schema/types/podcast.js +++ b/src/schema/types/podcast.js @@ -1,6 +1,8 @@ import { DateFormat } from "~/schema/enums" import Cover from "./podcastItem" import PodcastItem from "./podcastItem" +import Platforms from "./platforms" +import Socials from "./socials" const Podcast = `type Podcast { _id: String! @@ -27,10 +29,22 @@ const Podcast = `type Podcast { disabled: Boolean! feed_redirect_url: String web_redirect_url: String + platforms: Platforms! + socials: Socials! + wiki_url: String + shop_url: String + donate_url: String items: [PodcastItem]! ordering: String! _host: String! } ` -export default () => [DateFormat, PodcastItem, Podcast, Cover] +export default () => [ + DateFormat, + PodcastItem, + Podcast, + Cover, + Platforms, + Socials +] diff --git a/src/schema/types/resolvers/podcast.js b/src/schema/types/resolvers/podcast.js index da4873f9..77f56312 100644 --- a/src/schema/types/resolvers/podcast.js +++ b/src/schema/types/resolvers/podcast.js @@ -1,7 +1,7 @@ import moment from "moment" import Item from "~/connectors/item" import { DateFormat } from "~/schema/enums" -import { empty } from "~/utils" +import { empty, nullIfEmpty } from "~/utils" import path from "path" @@ -130,6 +130,53 @@ const Podcast = { ordering(feed) { return feed.ordering == "asc" ? "asc" : "desc" }, + platforms(feed) { + return { + apple: nullIfEmpty(feed.itunes), + google: nullIfEmpty(feed.google_podcasts), + spotify: nullIfEmpty(feed.spotify), + deezer: nullIfEmpty(feed.deezer), + podcloud: feed.identifier + } + }, + socials(feed) { + return { + youtube: nullIfEmpty(feed.youtube), + soundcloud: nullIfEmpty(feed.soundcloud), + dailymotion: nullIfEmpty(feed.dailymotion), + twitch: nullIfEmpty(feed.twitch), + twitter: nullIfEmpty(feed.twitter), + facebook: nullIfEmpty(feed.facebook), + instagram: nullIfEmpty(feed.instagram) + } + }, + wiki_url(feed) { + const url = feed.wiki + + if (empty(url)) return null + + if (!/^https?:\/\//i.test(url)) url = "http://" + url + + return url + }, + shop_url(feed) { + const url = feed.shop + + if (empty(url)) return null + + if (!/^https?:\/\//i.test(url)) url = "http://" + url + + return url + }, + donate_url(feed) { + const url = feed.donate + + if (empty(url)) return null + + if (!/^https?:\/\//i.test(url)) url = "http://" + url + + return url + }, items(feed) { return new Promise((resolve, reject) => { const findArgs = { diff --git a/src/schema/types/socials.js b/src/schema/types/socials.js new file mode 100644 index 00000000..8b4f9627 --- /dev/null +++ b/src/schema/types/socials.js @@ -0,0 +1,13 @@ +const Socials = ` +type Socials { + youtube: String + soundcloud: String + dailymotion: String + twitch: String + twitter: String + facebook: String + instagram: String +} +` + +export default () => [Socials] diff --git a/src/utils/index.js b/src/utils/index.js index 7762c3ea..aecea4ca 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -40,6 +40,10 @@ const empty = function(obj) { return !(typeof obj === "string" && obj.trim().length > 0) } +const nullIfEmpty = function(obj) { + return empty(obj) ? null : obj +} + const sanitize = text => empty(text) ? "" @@ -53,4 +57,4 @@ const sanitize = text => } ).trim() -export { empty, markdown, sanitize } +export { empty, nullIfEmpty, markdown, sanitize }