package main import ( "io" "log" "net/http" "strings" ) func IndexHandler(w http.ResponseWriter, _ *http.Request) { content := `

Feeds to archive

Input the URLs of the feeds you wish to archive below. You can add as many as needed, and access them through the website or API. Alternatively, include links to .opml files, and the feeds within will be archived.


You can also upload .opml files containing the feeds you wish to archive:

` FAQ := `

FAQ

What are web feeds?

Web feeds are a way to distribute content on the web. They allow users to access updates from websites without having to visit them directly. Feeds are typically used for news websites, blogs, and other sites that frequently update content.
You can read more about web feeds on Wikipedia.


What is FeedVault?

FeedVault is a service that archives web feeds. It allows users to access and search for historical content from various websites. The service is designed to preserve the history of the web and provide a reliable source for accessing content that may no longer be available on the original websites.


Why archive feeds?

Web feeds are a valuable source of information, and archiving them ensures that the content is preserved for future reference. By archiving feeds, we can ensure that historical content is available for research, analysis, and other purposes. Additionally, archiving feeds can help prevent the loss of valuable information due to website changes, outages, or other issues.


How does it work?

FeedVault is written in Go and uses the gofeed library to parse feeds. The service periodically checks for new content in the feeds and stores it in a database. Users can access the archived feeds through the website or API.


How can I access the archived feeds?

You can access the archived feeds through the website or API. The website provides a user interface for searching and browsing the feeds, while the API allows you to access the feeds programmatically. You can also download the feeds in various formats, such as JSON, XML, or RSS.

` content += FAQ htmlData := HTMLData{ Title: "FeedVault", Description: "FeedVault - A feed archive", Keywords: "RSS, Atom, Feed, Archive", Author: "TheLovinator", CanonicalURL: "http://localhost:8000/", Content: content, } html := fullHTML(htmlData) w.Write([]byte(html)) } func ApiHandler(w http.ResponseWriter, _ *http.Request) { htmlData := HTMLData{ Title: "FeedVault API", Description: "FeedVault API - A feed archive", Keywords: "RSS, Atom, Feed, Archive, API", Author: "TheLovinator", CanonicalURL: "http://localhost:8000/api", Content: "

Here be dragons.

", } html := fullHTML(htmlData) w.Write([]byte(html)) } func FeedsHandler(w http.ResponseWriter, _ *http.Request) { htmlData := HTMLData{ Title: "FeedVault Feeds", Description: "FeedVault Feeds - A feed archive", Keywords: "RSS, Atom, Feed, Archive", Author: "TheLovinator", CanonicalURL: "http://localhost:8000/feeds", Content: "

Here be feeds.

", } html := fullHTML(htmlData) w.Write([]byte(html)) } func AddFeedHandler(w http.ResponseWriter, r *http.Request) { var parseErrors []ParseResult // Parse the form and get the URLs r.ParseForm() urls := r.Form.Get("urls") if urls == "" { http.Error(w, "No URLs provided", http.StatusBadRequest) return } for _, feed_url := range strings.Split(urls, "\n") { // TODO: Try to upgrade to https if http is provided // Validate the URL err := validateURL(feed_url) if err != nil { parseErrors = append(parseErrors, ParseResult{FeedURL: feed_url, Msg: err.Error(), IsError: true}) continue } // "Add" the feed to the database log.Println("Adding feed:", feed_url) parseErrors = append(parseErrors, ParseResult{FeedURL: feed_url, Msg: "Added", IsError: false}) } htmlData := HTMLData{ Title: "FeedVault", Description: "FeedVault - A feed archive", Keywords: "RSS, Atom, Feed, Archive", Author: "TheLovinator", CanonicalURL: "http://localhost:8000/", Content: "

Feeds added.

", ParseResult: parseErrors, } html := fullHTML(htmlData) w.Write([]byte(html)) } func UploadOpmlHandler(w http.ResponseWriter, r *http.Request) { // Parse the form and get the file r.ParseMultipartForm(10 << 20) // 10 MB file, _, err := r.FormFile("file") if err != nil { http.Error(w, "No file provided", http.StatusBadRequest) return } defer file.Close() // Read the file all, err := io.ReadAll(file) if err != nil { http.Error(w, "Failed to read file", http.StatusInternalServerError) return } // Convert the file to a string opml := string(all) // Parse the OPML file parseResult := []ParseResult{} links, err := ParseOpml(opml) if err != nil { parseResult = append(parseResult, ParseResult{FeedURL: "/upload_opml", Msg: err.Error(), IsError: true}) } else { // Add the feeds to the database for _, feed_url := range links.XMLLinks { log.Println("Adding feed:", feed_url) // Validate the URL err := validateURL(feed_url) if err != nil { parseResult = append(parseResult, ParseResult{FeedURL: feed_url, Msg: err.Error(), IsError: true}) continue } parseResult = append(parseResult, ParseResult{FeedURL: feed_url, Msg: "Added", IsError: false}) } } // Return the results htmlData := HTMLData{ Title: "FeedVault", Description: "FeedVault - A feed archive", Keywords: "RSS, Atom, Feed, Archive", Author: "TheLovinator", CanonicalURL: "http://localhost:8000/", Content: "

Feeds added.

", ParseResult: parseResult, } html := fullHTML(htmlData) w.Write([]byte(html)) }