-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
188 lines (174 loc) · 5.41 KB
/
index.html
File metadata and controls
188 lines (174 loc) · 5.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>RSS Feed Subscriber</title>
<style>
body {
font-family: system-ui, -apple-system, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
line-height: 1.6;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: 500;
}
input {
width: 100%;
padding: 8px;
margin-bottom: 10px;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
}
.button-group {
display: flex;
gap: 10px;
flex-wrap: wrap;
justify-content: flex-start;
}
button {
background: #007bff;
color: white;
border: none;
padding: 8px 16px;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background: #0056b3;
}
#response {
margin-top: 20px;
padding: 10px;
border-radius: 4px;
white-space: pre-wrap;
}
.success {
background: #d4edda;
color: #155724;
}
.error {
background: #f8d7da;
color: #721c24;
}
</style>
</head>
<body>
<h1>RSS Feed Subscriber</h1>
<p>
An app to subscribe to RSS feeds, and receive daily email notifications.
Built using val.town serverless functions, and currently configured for
personal use only.
</p>
<div class="form-group">
<label for="apiKey">API Key:</label>
<input type="password" id="apiKey" placeholder="Enter your API key" />
</div>
<div class="form-group">
<label for="feedUrl">Feed URL:</label>
<input type="text" id="feedUrl" placeholder="Enter RSS feed URL" />
</div>
<div class="button-group">
<button onclick="addFeed()">Add Feed</button>
<button onclick="deleteFeed()">Delete Feed</button>
<button onclick="getFeeds()">Get All Feeds</button>
<button onclick="getPosts()">Get Posts (last 3 months)</button>
</div>
<div id="response"></div>
<script>
const API_BASE = "https://thomasvn-rss-sub.val.run";
// ----------------------------------------------------------------------
// BUTTON HANDLERS
// ----------------------------------------------------------------------
function addFeed() {
const apiKey = document.getElementById("apiKey").value;
const url = document.getElementById("feedUrl").value;
if (!apiKey) {
displayResponse("Please enter an API key", "error");
return;
}
if (!url) {
displayResponse("Please enter a feed URL", "error");
return;
}
makeRequest(`/add?url=${encodeURIComponent(url)}`, apiKey);
}
function deleteFeed() {
const apiKey = document.getElementById("apiKey").value;
const url = document.getElementById("feedUrl").value;
if (!apiKey) {
displayResponse("Please enter an API key", "error");
return;
}
if (!url) {
displayResponse("Please enter a feed URL", "error");
return;
}
makeRequest(`/delete?url=${encodeURIComponent(url)}`, apiKey);
}
function getFeeds() {
makeRequest("/get");
}
function getPosts() {
makeRequest("/posts");
}
// ----------------------------------------------------------------------
// HELPERS
// ----------------------------------------------------------------------
async function makeRequest(endpoint, apiKey = null) {
try {
const headers = apiKey ? { Authorization: `Bearer ${apiKey}` } : {};
const response = await fetch(`${API_BASE}${endpoint}`, {
method: "GET",
headers,
});
const data = await response.text();
displayResponse(data, response.ok ? "success" : "error");
} catch (error) {
displayResponse(error.message, "error");
}
}
function displayResponse(message, type) {
const responseDiv = document.getElementById("response");
responseDiv.className = type;
try {
const data = JSON.parse(message);
if (Array.isArray(data) && data.length && data[0].url) {
// Display feeds as a list
responseDiv.innerHTML =
"<ul>" +
data.map((feed) => `<li>${feed.url}</li>`).join("") +
"</ul>";
} else if (Array.isArray(data) && data.length && data[0].title) {
// Display blog posts as formatted list
responseDiv.innerHTML =
"<ul>" +
data
.map(
(post) =>
`<li><strong>${post.feedTitle}</strong><br>` +
`<em>${post.pubDate}</em><br>` +
`<a href="${post.link}" target="_blank">${post.title}</a></li>`
)
.join("") +
"</ul>";
} else {
// Display other data as JSON
responseDiv.textContent = JSON.stringify(data, null, 2);
}
} catch {
// Fallback to plain text
responseDiv.textContent = message;
}
}
</script>
</body>
</html>