Skip to content

Commit

Permalink
feat: adds social and platform links
Browse files Browse the repository at this point in the history
  • Loading branch information
PofMagicfingers committed Nov 9, 2020
1 parent b23dc48 commit 3aeb977
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 6 deletions.
17 changes: 16 additions & 1 deletion src/connectors/feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 16 additions & 1 deletion src/schema/queries/resolvers/podcastForFeedWithIdentifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 13 additions & 1 deletion src/schema/queries/resolvers/podcasts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
11 changes: 11 additions & 0 deletions src/schema/types/platforms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const Platforms = `
type Platforms {
apple: String
google: String
spotify: String
deezer: String
podcloud: String
}
`

export default () => [Platforms]
16 changes: 15 additions & 1 deletion src/schema/types/podcast.js
Original file line number Diff line number Diff line change
@@ -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!
Expand All @@ -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
]
49 changes: 48 additions & 1 deletion src/schema/types/resolvers/podcast.js
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -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 = {
Expand Down
13 changes: 13 additions & 0 deletions src/schema/types/socials.js
Original file line number Diff line number Diff line change
@@ -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]
6 changes: 5 additions & 1 deletion src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
? ""
Expand All @@ -53,4 +57,4 @@ const sanitize = text =>
}
).trim()

export { empty, markdown, sanitize }
export { empty, nullIfEmpty, markdown, sanitize }

0 comments on commit 3aeb977

Please sign in to comment.