From 0bc687a53873a7dc12743786b472b524730bf2c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Hells=C3=A9n?= Date: Sun, 4 Feb 2024 22:04:22 +0100 Subject: [PATCH] Add terms and FAQ --- main.go | 5 ++ main_test.go | 150 +++++++++++++++++++++++++++++++++++++++++ templates/base.tmpl | 2 +- templates/index.tmpl | 37 ++++++++++ templates/privacy.tmpl | 2 - templates/terms.tmpl | 34 ++++++++++ 6 files changed, 227 insertions(+), 3 deletions(-) create mode 100644 templates/terms.tmpl diff --git a/main.go b/main.go index 67b5de7..c8d1fb8 100644 --- a/main.go +++ b/main.go @@ -59,6 +59,7 @@ func main() { r.Get("/donate", DonateHandler) r.Get("/feeds", FeedsHandler) r.Get("/privacy", PrivacyHandler) + r.Get("/terms", TermsHandler) r.Post("/add", AddFeedHandler) r.Handle("/static/*", http.StripPrefix("/static/", http.FileServer(http.Dir("static")))) @@ -220,6 +221,10 @@ func PrivacyHandler(w http.ResponseWriter, _ *http.Request) { renderPage(w, "Privacy", "Privacy Page", "privacy, page", "TheLovinator", "http://localhost:8000/privacy", "privacy") } +func TermsHandler(w http.ResponseWriter, _ *http.Request) { + renderPage(w, "Terms", "Terms and Conditions Page", "terms, page", "TheLovinator", "http://localhost:8000/terms", "terms") +} + // Run some simple validation on the URL func validateURL(feed_url string) error { // Check if URL starts with http or https diff --git a/main_test.go b/main_test.go index 4e51aa2..3699bfa 100644 --- a/main_test.go +++ b/main_test.go @@ -260,3 +260,153 @@ func TestApiHandler(t *testing.T) { body, shouldContain) } } + +func TestTermsHandler(t *testing.T) { + // Create a request to pass to our handler. + req, err := http.NewRequest("GET", "/terms", nil) + if err != nil { + t.Fatal(err) + } + + // We create a ResponseRecorder (which satisfies http.ResponseWriter) to record the response. + rr := httptest.NewRecorder() + handler := http.HandlerFunc(TermsHandler) + + // Our handlers satisfy http.Handler, so we can call their ServeHTTP method + // directly and pass in our Request and ResponseRecorder. + handler.ServeHTTP(rr, req) + + // Check the status code is what we expect. + if status := rr.Code; status != http.StatusOK { + t.Errorf("handler returned wrong status code: got %v want %v", + status, http.StatusOK) + } + + // Check the response contains the expected string. + shouldContain := "Terms of Service" + body := rr.Body.String() + if !assert.Contains(t, body, shouldContain) { + t.Errorf("handler returned unexpected body: got %v want %v", + body, shouldContain) + } +} + +func TestPrivacyHandler(t *testing.T) { + // Create a request to pass to our handler. + req, err := http.NewRequest("GET", "/privacy", nil) + if err != nil { + t.Fatal(err) + } + + // We create a ResponseRecorder (which satisfies http.ResponseWriter) to record the response. + rr := httptest.NewRecorder() + handler := http.HandlerFunc(PrivacyHandler) + + // Our handlers satisfy http.Handler, so we can call their ServeHTTP method + // directly and pass in our Request and ResponseRecorder. + handler.ServeHTTP(rr, req) + + // Check the status code is what we expect. + if status := rr.Code; status != http.StatusOK { + t.Errorf("handler returned wrong status code: got %v want %v", + status, http.StatusOK) + } + + // Check the response contains the expected string. + shouldContain := "Privacy Policy" + body := rr.Body.String() + if !assert.Contains(t, body, shouldContain) { + t.Errorf("handler returned unexpected body: got %v want %v", + body, shouldContain) + } +} + +func TestNotFoundHandler(t *testing.T) { + // Create a request to pass to our handler. + req, err := http.NewRequest("GET", "/notfound", nil) + if err != nil { + t.Fatal(err) + } + + // We create a ResponseRecorder (which satisfies http.ResponseWriter) to record the response. + rr := httptest.NewRecorder() + handler := http.HandlerFunc(NotFoundHandler) + + // Our handlers satisfy http.Handler, so we can call their ServeHTTP method + // directly and pass in our Request and ResponseRecorder. + handler.ServeHTTP(rr, req) + + // Check the status code is what we expect. + if status := rr.Code; status != http.StatusNotFound { + t.Errorf("handler returned wrong status code: got %v want %v", + status, http.StatusNotFound) + } + + // Check the response contains the expected string. + shouldContain := "

404 - Page not found

" + body := rr.Body.String() + if !assert.Contains(t, body, shouldContain) { + t.Errorf("handler returned unexpected body: got %v want %v", + body, shouldContain) + } +} + +func TestMethodNotAllowedHandler(t *testing.T) { + // Create a request to pass to our handler. + req, err := http.NewRequest("GET", "/api", nil) + if err != nil { + t.Fatal(err) + } + + // We create a ResponseRecorder (which satisfies http.ResponseWriter) to record the response. + rr := httptest.NewRecorder() + handler := http.HandlerFunc(MethodNotAllowedHandler) + + // Our handlers satisfy http.Handler, so we can call their ServeHTTP method + // directly and pass in our Request and ResponseRecorder. + handler.ServeHTTP(rr, req) + + // Check the status code is what we expect. + if status := rr.Code; status != http.StatusMethodNotAllowed { + t.Errorf("handler returned wrong status code: got %v want %v", + status, http.StatusMethodNotAllowed) + } + + // Check the response contains the expected string. + shouldContain := "

405 - Method Not Allowed

" + body := rr.Body.String() + if !assert.Contains(t, body, shouldContain) { + t.Errorf("handler returned unexpected body: got %v want %v", + body, shouldContain) + } +} + +func TestDonateHandler(t *testing.T) { + // Create a request to pass to our handler. + req, err := http.NewRequest("GET", "/donate", nil) + if err != nil { + t.Fatal(err) + } + + // We create a ResponseRecorder (which satisfies http.ResponseWriter) to record the response. + rr := httptest.NewRecorder() + handler := http.HandlerFunc(DonateHandler) + + // Our handlers satisfy http.Handler, so we can call their ServeHTTP method + // directly and pass in our Request and ResponseRecorder. + handler.ServeHTTP(rr, req) + + // Check the status code is what we expect. + if status := rr.Code; status != http.StatusOK { + t.Errorf("handler returned wrong status code: got %v want %v", + status, http.StatusOK) + } + + // Check the response contains the expected string. + shouldContain := "tl;dr: GitHub Sponsors" + body := rr.Body.String() + if !assert.Contains(t, body, shouldContain) { + t.Errorf("handler returned unexpected body: got %v want %v", + body, shouldContain) + } +} diff --git a/templates/base.tmpl b/templates/base.tmpl index f943530..2785657 100644 --- a/templates/base.tmpl +++ b/templates/base.tmpl @@ -68,7 +68,7 @@ hello@feedvault.se
- Terms of Service | Privacy Policy + Terms of Service | Privacy Policy
diff --git a/templates/index.tmpl b/templates/index.tmpl index e22928b..cf83db6 100644 --- a/templates/index.tmpl +++ b/templates/index.tmpl @@ -13,4 +13,41 @@ + +

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. +

+
{{ end }} diff --git a/templates/privacy.tmpl b/templates/privacy.tmpl index a9caa1a..d002c4a 100644 --- a/templates/privacy.tmpl +++ b/templates/privacy.tmpl @@ -1,5 +1,4 @@ {{ define "content" }} -

Privacy Policy

@@ -48,5 +47,4 @@

Cloudflare's contact information can be found here.

-
{{ end }} diff --git a/templates/terms.tmpl b/templates/terms.tmpl new file mode 100644 index 0000000..5880947 --- /dev/null +++ b/templates/terms.tmpl @@ -0,0 +1,34 @@ +{{ define "content" }} +
+
+

Terms of Service

+
+

+ Last Updated: + +

+
+

Content Policy

+

+ Users are prohibited from uploading any content that is illegal under Swedish law. Any such content found on our platform will be removed. If this happens repeatedly, the user will be banned from using our platform. +
+
+ You can report any content that you believe violates our content policy by sending an email to hello@feedvault.se. Please include the URL of the content in question and a brief description of why you believe it violates our content policy. +

+

Copyright Policy

+

+ We will remove URLs that are used to share copyrightable information without the necessary permissions or licenses. +

+

Web Scraping

+

+ Web scraping is permitted on our platform. We currently do not impose a rate limit on requests. +

+

API Usage

+

+ Our API is free to use. We do not impose any rate limits on requests. +

+
+
+{{ end }}