-
-
Save bbielsa/7d131aa2188945f591a8379ec0defc9b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
when "import_youtube" | |
filename = part.filename || "" | |
extension = filename.split(".").last | |
if extension == "xml" && (type == "application/xml" || type == "text/xml") | |
subscriptions = XML.parse(body) | |
user.subscriptions += subscriptions.xpath_nodes(%q(//outline[@type="rss"])).map do |channel| | |
channel["xmlUrl"].match(/UC[a-zA-Z0-9_-]{22}/).not_nil![0] | |
end | |
elsif extension == "json" && type == "application/json" | |
subscriptions = JSON.parse(body) | |
user.subscriptions += subscriptions.as_a.compact_map do |entry| | |
entry["snippet"]["resourceId"]["channelId"].as_s | |
end | |
elsif extension == "csv" && type == "text/csv" | |
subscriptions = parse_subscription_export_csv(body) | |
user.subscriptions += subscriptions | |
else | |
next error_template(400, "Invalid subscription file uploaded") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment