# Please enter the commit message for your changes. Lines starting

# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch main
#
# Initial commit
#
# Changes to be committed:
#	new file:   README.md
#	new file:   index.html
#	new file:   index.md
#	new file:   url.json
#	new file:   url/pic/all.csv
#	new file:   url/pic/fjht.csv
#	new file:   url/pic/whitebackground.csv
#	new file:   url/video/all.csv
#	new file:   "worker 302\350\267\263\350\275\254.js"
#	new file:   "worker \344\270\215\350\267\263\350\275\254.js"
#
This commit is contained in:
wood chen 2024-01-16 21:49:13 +08:00
commit 782adaf8eb
10 changed files with 341 additions and 0 deletions

40
README.md Normal file
View File

@ -0,0 +1,40 @@
# Random-Api 随机文件API
**请给个star谢谢**
## 完整说明请查看:
[https://random-api.woodchen.ink](https://random-api.woodchen.ink)
> 我的博客说明:[https://woodchen.ink/archives/1705367469203](https://woodchen.ink/archives/1705367469203)
使用cloudflare worker配合github网页发布功能实现获取path与csv_path关系`url.csv` 文件中给出的链接来实现一个随机文件
不仅可以放图片,还能放文本文件,视频,等等
## 感谢
大部分图片来自网络分享的API
以下不分先后:
* https://t.mwm.moe/
## 自行部署
1. cloudflare 新建一个worker把 worker.js文件的代码粘贴进去保存可以修改为自己的链接
2. 访问即可
## 赞赏
如果对这个项目对你有帮助,欢迎打赏,支持微信和支付宝,请留言和备注项目,我会在我的博客上写出,感谢。
### 微信
![1705312445316.png](https://cdn-img-r2.czl.net/2024/01/15/65a501199193b.png)
### 支付宝
![1705312348956.png](https://cdn-img-r2.czl.net/2024/01/15/65a50089b4b92.png)

117
index.html Normal file
View File

@ -0,0 +1,117 @@
<!DOCTYPE html>
<html>
<head>
<title>随机文件api-wood</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="shortcut icon" size="32x32" href="https://cdn-img-r2.czl.net/woodchenink/2024/1/14/blackwood.jpg">
<style>
html,
body {
margin: 0;
color: #424242;
font-weight: 300;
font-family: "-apple-system", "BlinkMacSystemFont", "Helvetica Neue", "PingFang SC", "Microsoft YaHei",
"Source Han Sans SC", "Noto Sans CJK SC", "WenQuanYi Micro Hei", "sans-serif";
}
* {
box-sizing: border-box;
}
header {
padding: 40vh 0 8vh 0;
text-align: center;
font-weight: 100;
display: positive;
/* flex-direction: column; */
/* align-items: center; */
justify-content: space-between;
/* height: 100vh; */
overflow: hidden;
background: #6495ED;
}
#scroll-down {
background-color: transparent;
margin-top: 2rem;
width: 2rem;
height: 2rem;
border-radius: 50%;
border: 2px solid #424242;
cursor: pointer;
animation: bounce 2s infinite 2s;
}
#scroll-down::before {
display: block;
content: "";
transform: rotate(-45deg) translate(0.15rem, 0.15rem);
width: 0.4rem;
height: 0.4rem;
border: 2px solid #424242;
border-width: 0px 0 2px 2px;
}
main {
padding: 1vw;
}
section {
padding: 1rem;
}
section {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
/* height: 100vh; */
/* 使section占据整个视窗高度你可以根据需要调整这个值 */
}
img {
width: 150px;
height: 200px;
object-fit: cover;
}
</style>
<link rel="stylesheet" href="https://unpkg.com/mdui@2.0.3/mdui.css">
<script src="https://unpkg.com/mdui@2.0.3/mdui.global.js"></script>
<script src="https://cdnjs.czl.net/ajax/libs/markdown-it/13.0.2/markdown-it.min.js"></script>
</head>
<body class="mdui-prose">
<mdui-layout>
<header>
<section>
<h1>Random-Api / 随机文件API </h1>
<h3>wood</h3>
</section>
<button id="scroll-down"></button>
</header>
<main style="margin:20px auto;">
<div id="markdown-content">
</div>
</main>
</mdui-layout>
<!-- 渲染markdown -->
<script>
// 创建带有配置的 markdown-it 实例
var md = window.markdownit({
html: true
});
// 异步加载 readme.md 文件内容
fetch('https://raw.githubusercontent.com/woodchen-ink/Random-Api/master/index.md')
.then(response => response.text())
.then(markdownText => {
// 渲染 Markdown 内容
document.getElementById('markdown-content').innerHTML = md.render(markdownText);
})
.catch(error => console.error('Error loading readme.md:', error));
</script>
</body>
</html>

45
index.md Normal file
View File

@ -0,0 +1,45 @@
# Random-Api 随机文件API
github地址 [https://github.com/woodchen-ink/Random-Api](https://github.com/woodchen-ink/Random-Api)
> 我的博客说明:[https://woodchen.ink/archives/1705367469203](https://woodchen.ink/archives/1705367469203)
使用cloudflare worker配合github网页发布功能实现获取path与csv_path关系`url.csv` 文件中给出的链接来实现一个随机文件
不仅可以放图片,还能放文本文件,视频,等等
## 接口
| 类型 | 种类 | 请求地址 |
| ---- | ---------- | ---------------- |
| 图片 | 所有 | [https://random-api.woodchen.ink/pic/all](https://random-api.woodchen.ink/pic/all) |
| 图片 | 白底 | [https://random-api.woodchen.ink/pic/whitebackground](https://random-api.woodchen.ink/pic/whitebackground) |
| 图片 | 风景横图 | [https://random-api.woodchen.ink/pic/fjht](https://random-api.woodchen.ink/pic/fjht) |
| 视频 | 所有 | [https://random-api.woodchen.ink/video/all](https://random-api.woodchen.ink/video/all) |
## 感谢
大部分图片来自网络分享的API
以下不分先后:
* https://t.mwm.moe/
## 自行部署
1. cloudflare 新建一个worker把 worker.js文件的代码粘贴进去保存可以修改为自己的链接
2. 访问即可
## 赞赏
如果对这个项目对你有帮助,欢迎打赏,支持微信和支付宝,请留言和备注项目,我会在我的博客上写出,感谢。
### 微信
![1705312445316.png](https://cdn-img-r2.czl.net/2024/01/15/65a501199193b.png)
### 支付宝
![1705312348956.png](https://cdn-img-r2.czl.net/2024/01/15/65a50089b4b92.png)

11
url.json Normal file
View File

@ -0,0 +1,11 @@
{
"pic": {
"all": "https://raw.githubusercontent.com/woodchen-ink/Random-Api/master/url/pic/all.csv",
"fjht": "https://raw.githubusercontent.com/woodchen-ink/Random-Api/master/url/pic/fjht.csv",
"whitebackground": "https://raw.githubusercontent.com/woodchen-ink/Random-Api/master/url/pic/whitebackground.csv"
},
"video": {
"all": "https://raw.githubusercontent.com/woodchen-ink/Random-Api/master/url/video/all.csv"
}
}

11
url/pic/all.csv Normal file
View File

@ -0,0 +1,11 @@
https://t.mwm.moe/ycy/
https://t.mwm.moe/ai
https://t.mwm.moe/moez
https://t.mwm.moe/ysz
https://t.mwm.moe/fj
https://t.mwm.moe/lai
https://t.mwm.moe/xhl
https://cdn.seovx.com/?mom=302
http://www.dmoe.cc/random.php
http://api.mtyqx.cn/api/random.php
https://api.r10086.com/樱道随机图片api接口.php?图片系列=动漫综合2
1 https://t.mwm.moe/ycy/
2 https://t.mwm.moe/ai
3 https://t.mwm.moe/moez
4 https://t.mwm.moe/ysz
5 https://t.mwm.moe/fj
6 https://t.mwm.moe/lai
7 https://t.mwm.moe/xhl
8 https://cdn.seovx.com/?mom=302
9 http://www.dmoe.cc/random.php
10 http://api.mtyqx.cn/api/random.php
11 https://api.r10086.com/樱道随机图片api接口.php?图片系列=动漫综合2

2
url/pic/fjht.csv Normal file
View File

@ -0,0 +1,2 @@
https://t.mwm.moe/fj
https://api.isoyu.com/aipc_scenery.php
1 https://t.mwm.moe/fj
2 https://api.isoyu.com/aipc_scenery.php

View File

@ -0,0 +1 @@
https://t.mwm.moe/bd
1 https://t.mwm.moe/bd

2
url/video/all.csv Normal file
View File

@ -0,0 +1,2 @@
https://cdn-img.czl.net/woodchenink/2024/1/16/%E6%B5%AA%E5%AE%A2%E5%89%91%E5%BF%83%E8%BF%BD%E5%BF%86%E7%AF%8730%E5%B8%A71080P%E6%97%A0%E5%A3%B0%E9%9F%B3.mp4
https://t.mwm.moe/acg/acg
1 https://cdn-img.czl.net/woodchenink/2024/1/16/%E6%B5%AA%E5%AE%A2%E5%89%91%E5%BF%83%E8%BF%BD%E5%BF%86%E7%AF%8730%E5%B8%A71080P%E6%97%A0%E5%A3%B0%E9%9F%B3.mp4
2 https://t.mwm.moe/acg/acg

56
worker 302跳转.js Normal file
View File

@ -0,0 +1,56 @@
// 外部 JSON 文件的 URL
const CSV_PATHS_URL = 'https://raw.githubusercontent.com/woodchen-ink/Random-Api/master/url.json';
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});
// 处理请求
async function handleRequest(request) {
const csvPathsResponse = await fetch(CSV_PATHS_URL);
if (!csvPathsResponse.ok) {
return new Response('CSV paths configuration could not be fetched.', { status: 500 });
}
const csvPaths = await csvPathsResponse.json();
const url = new URL(request.url);
let path = url.pathname.slice(1); // 移除路径前的斜杠
path = path.split('?')[0]; // 移除问号后的部分
if (path.endsWith('/')) {
path = path.slice(0, -1); // 移除路径后的斜杠
}
// 分割路径得到前缀和后缀
const pathSegments = path.split('/');
const prefix = pathSegments[0];
const suffix = pathSegments.slice(1).join('/');
// 如果路径是 CSV 资源路径
if (prefix in csvPaths && suffix in csvPaths[prefix]) {
const csvUrl = csvPaths[prefix][suffix];
const fileArrayResponse = await fetch(csvUrl);
if (fileArrayResponse.ok) {
const fileArrayText = await fileArrayResponse.text();
const fileArray = fileArrayText.split('\n').filter(Boolean); // 过滤掉空行
const randomIndex = Math.floor(Math.random() * fileArray.length);
const randomUrl = fileArray[randomIndex];
// 用原请求的头部创建新的请求对象
const resourceRequest = new Request(randomUrl, {
headers: request.headers
});
// 直接从随机 URL 获取图片内容并返回
return fetch(resourceRequest);
} else {
return new Response('CSV file could not be fetched.', { status: 500 });
}
} else {
// 如果不是 CSV 资源路径,返回 index.html 内容
const indexHtmlResponse = await fetch('https://raw.githubusercontent.com/woodchen-ink/Random-Api/master/index.html');
return new Response(indexHtmlResponse.body, {
headers: { 'Content-Type': 'text/html' },
});
}
}

56
worker 不跳转.js Normal file
View File

@ -0,0 +1,56 @@
// 外部 JSON 文件的 URL
const CSV_PATHS_URL = 'https://raw.githubusercontent.com/woodchen-ink/Random-Api/master/url.json';
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});
// 处理请求
async function handleRequest(request) {
const csvPathsResponse = await fetch(CSV_PATHS_URL);
if (!csvPathsResponse.ok) {
return new Response('CSV paths configuration could not be fetched.', { status: 500 });
}
const csvPaths = await csvPathsResponse.json();
const url = new URL(request.url);
let path = url.pathname.slice(1); // 移除路径前的斜杠
path = path.split('?')[0]; // 移除问号后的部分
if (path.endsWith('/')) {
path = path.slice(0, -1); // 移除路径后的斜杠
}
// 分割路径得到前缀和后缀
const pathSegments = path.split('/');
const prefix = pathSegments[0];
const suffix = pathSegments.slice(1).join('/');
// 如果路径是 CSV 资源路径
if (prefix in csvPaths && suffix in csvPaths[prefix]) {
const csvUrl = csvPaths[prefix][suffix];
const fileArrayResponse = await fetch(csvUrl);
if (fileArrayResponse.ok) {
const fileArrayText = await fileArrayResponse.text();
const fileArray = fileArrayText.split('\n').filter(Boolean); // 过滤掉空行
const randomIndex = Math.floor(Math.random() * fileArray.length);
const randomUrl = fileArray[randomIndex];
// 用原请求的头部创建新的请求对象
const resourceRequest = new Request(randomUrl, {
headers: request.headers
});
// 直接从随机 URL 获取图片内容并返回
return fetch(resourceRequest);
} else {
return new Response('CSV file could not be fetched.', { status: 500 });
}
} else {
// 如果不是 CSV 资源路径,返回 index.html 内容
const indexHtmlResponse = await fetch('https://raw.githubusercontent.com/woodchen-ink/Random-Api/master/index.html');
return new Response(indexHtmlResponse.body, {
headers: { 'Content-Type': 'text/html' },
});
}
}