roast-api 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/release.yml +0 -23
- package/README.md +16 -1
- package/api/client.js +44 -12
- package/index.html +2 -1
- package/package.json +2 -2
|
@@ -28,26 +28,3 @@ jobs:
|
|
|
28
28
|
files: |
|
|
29
29
|
api/client.js
|
|
30
30
|
postman/roast-as-a-service.postman_collection.json
|
|
31
|
-
|
|
32
|
-
publish-github-packages:
|
|
33
|
-
runs-on: ubuntu-latest
|
|
34
|
-
permissions:
|
|
35
|
-
contents: read
|
|
36
|
-
packages: write
|
|
37
|
-
steps:
|
|
38
|
-
- uses: actions/checkout@v4
|
|
39
|
-
|
|
40
|
-
- uses: actions/setup-node@v4
|
|
41
|
-
with:
|
|
42
|
-
node-version: '20.x'
|
|
43
|
-
registry-url: 'https://npm.pkg.github.com'
|
|
44
|
-
scope: '@maizied'
|
|
45
|
-
|
|
46
|
-
- name: Update package name for GitHub Packages
|
|
47
|
-
run: |
|
|
48
|
-
sed -i 's/"name": "roast-api"/"name": "@maizied\/roast-api"/' package.json
|
|
49
|
-
cat package.json
|
|
50
|
-
|
|
51
|
-
- run: npm publish
|
|
52
|
-
env:
|
|
53
|
-
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
package/README.md
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
</p>
|
|
6
6
|
<p align="center">
|
|
7
7
|
<img src="https://hits.sh/maijied.github.io/roast-as-a-service.svg?view=today-total&style=flat-square&label=visitors&color=ec4899&labelColor=020617" alt="Visitor Count" />
|
|
8
|
+
<a href="https://www.npmjs.com/package/roast-api"><img src="https://img.shields.io/npm/v/roast-api?style=flat-square&color=f97316&labelColor=020617" alt="npm version" /></a>
|
|
8
9
|
</p>
|
|
9
10
|
|
|
10
11
|
Random developer roasts, delivered via a blazing‑fast static API on GitHub Pages. Plug it into your apps, bots, terminals, or CI logs when “nice error messages” just aren’t enough.
|
|
@@ -39,6 +40,8 @@ Use it when you want your:
|
|
|
39
40
|
### 1. Install via npm
|
|
40
41
|
```bash
|
|
41
42
|
npm install roast-api
|
|
43
|
+
# or
|
|
44
|
+
npm install @maizied/roast-as-a-service
|
|
42
45
|
```
|
|
43
46
|
|
|
44
47
|
```javascript
|
|
@@ -165,4 +168,16 @@ RaaS is a proud member of the **Lorapok** family. Check out our other tools:
|
|
|
165
168
|
- **[Lorapok CLI](https://github.com/Maijied/lorapok):** The intelligent AI agent framework for developers.
|
|
166
169
|
- **[Lorapok Media Player](https://github.com/Maijied/Lorapok_Media_Player):** A modern, feature-rich media player built for power users.
|
|
167
170
|
|
|
168
|
-
---
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## 👤 Author
|
|
174
|
+
|
|
175
|
+
**Maizied**
|
|
176
|
+
📧 [mdshuvo40@gmail.com](mailto:mdshuvo40@gmail.com)
|
|
177
|
+
🔗 [GitHub](https://github.com/Maijied) · [npm](https://www.npmjs.com/~maizied)
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## 📄 License
|
|
182
|
+
|
|
183
|
+
MIT © Maizied
|
package/api/client.js
CHANGED
|
@@ -3,9 +3,11 @@ const RaaS = (() => {
|
|
|
3
3
|
const CACHE_TTL_MS = 1000 * 60 * 60 * 24; // 24h
|
|
4
4
|
|
|
5
5
|
let manifestCache = null;
|
|
6
|
+
let memoryCache = {};
|
|
6
7
|
|
|
8
|
+
// Universal fetch (works in Node.js 18+ and browsers)
|
|
7
9
|
async function fetchJSON(url) {
|
|
8
|
-
const res = await fetch(url
|
|
10
|
+
const res = await fetch(url);
|
|
9
11
|
if (!res.ok) throw new Error('Network error');
|
|
10
12
|
return res.json();
|
|
11
13
|
}
|
|
@@ -23,24 +25,41 @@ const RaaS = (() => {
|
|
|
23
25
|
|
|
24
26
|
function readLocalCache(lang, shard) {
|
|
25
27
|
const key = getLocalCacheKey(lang, shard);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
if (
|
|
28
|
+
|
|
29
|
+
// Try localStorage (browser)
|
|
30
|
+
if (typeof localStorage !== 'undefined') {
|
|
31
|
+
const raw = localStorage.getItem(key);
|
|
32
|
+
if (!raw) return null;
|
|
33
|
+
try {
|
|
34
|
+
const parsed = JSON.parse(raw);
|
|
35
|
+
if (Date.now() - parsed.ts > CACHE_TTL_MS) {
|
|
36
|
+
localStorage.removeItem(key);
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
return parsed.data;
|
|
40
|
+
} catch {
|
|
31
41
|
localStorage.removeItem(key);
|
|
32
42
|
return null;
|
|
33
43
|
}
|
|
34
|
-
return parsed.data;
|
|
35
|
-
} catch {
|
|
36
|
-
localStorage.removeItem(key);
|
|
37
|
-
return null;
|
|
38
44
|
}
|
|
45
|
+
|
|
46
|
+
// Fallback to memory cache (Node.js)
|
|
47
|
+
const cached = memoryCache[key];
|
|
48
|
+
if (cached && Date.now() - cached.ts <= CACHE_TTL_MS) {
|
|
49
|
+
return cached.data;
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
39
52
|
}
|
|
40
53
|
|
|
41
54
|
function writeLocalCache(lang, shard, data) {
|
|
42
55
|
const key = getLocalCacheKey(lang, shard);
|
|
43
|
-
|
|
56
|
+
const cacheObj = { ts: Date.now(), data };
|
|
57
|
+
|
|
58
|
+
if (typeof localStorage !== 'undefined') {
|
|
59
|
+
localStorage.setItem(key, JSON.stringify(cacheObj));
|
|
60
|
+
} else {
|
|
61
|
+
memoryCache[key] = cacheObj;
|
|
62
|
+
}
|
|
44
63
|
}
|
|
45
64
|
|
|
46
65
|
function pickRandomIndex(max) {
|
|
@@ -81,14 +100,27 @@ const RaaS = (() => {
|
|
|
81
100
|
return {
|
|
82
101
|
language: shardData.language,
|
|
83
102
|
shard: shardData.shard,
|
|
103
|
+
id: roast.id,
|
|
84
104
|
text: roast.text,
|
|
85
105
|
intensity: roast.intensity,
|
|
86
106
|
length: roast.length
|
|
87
107
|
};
|
|
88
108
|
}
|
|
89
109
|
|
|
90
|
-
|
|
110
|
+
const api = {
|
|
91
111
|
getRandomRoast,
|
|
92
112
|
getManifest
|
|
93
113
|
};
|
|
114
|
+
|
|
115
|
+
// CommonJS export for Node.js
|
|
116
|
+
if (typeof module !== 'undefined' && module.exports) {
|
|
117
|
+
module.exports = api;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return api;
|
|
94
121
|
})();
|
|
122
|
+
|
|
123
|
+
// For browser global usage
|
|
124
|
+
if (typeof window !== 'undefined') {
|
|
125
|
+
window.RaaS = RaaS;
|
|
126
|
+
}
|
package/index.html
CHANGED
|
@@ -221,7 +221,8 @@ async function getRandomRoast(lang = 'en') {
|
|
|
221
221
|
<footer class="footer">
|
|
222
222
|
<p>Roast as a Service · Static JSON over CDN · Built on GitHub Pages.</p>
|
|
223
223
|
<p>A <a href="https://github.com/Maijied/lorapok">Lorapok</a> Project · <a
|
|
224
|
-
href="https://github.com/maijied/roast-as-a-service">View source</a
|
|
224
|
+
href="https://github.com/maijied/roast-as-a-service">View source</a> · Made by <a
|
|
225
|
+
href="mailto:mdshuvo40@gmail.com">Maizied</a></p>
|
|
225
226
|
<div style="margin-top: 10px; opacity: 0.8;">
|
|
226
227
|
<img src="https://hits.sh/maijied.github.io/roast-as-a-service.svg?view=today-total&style=flat-square&label=visitors&color=ec4899&labelColor=020617"
|
|
227
228
|
alt="Visitor Count" />
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "roast-api",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A static JSON API for delivering developer roasts.",
|
|
5
5
|
"main": "api/client.js",
|
|
6
6
|
"scripts": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"fun",
|
|
21
21
|
"lorapok"
|
|
22
22
|
],
|
|
23
|
-
"author": "Maizied",
|
|
23
|
+
"author": "Maizied <mdshuvo40@gmail.com>",
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"bugs": {
|
|
26
26
|
"url": "https://github.com/Maijied/roast-as-a-service/issues"
|