WorkerJS_CloudFlare_ImageBed/cloudflare-page/OneAPI-imgbed.html

94 lines
4.1 KiB
HTML
Raw Normal View History

2024-03-26 13:42:43 +08:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>文件上传</title>
2024-03-28 14:34:03 +08:00
<!--
本代码完全开源仅供学习CloudFlare Page和Worker组件编程使用
仓库地址 https://github.com/BlueSkyXN/WorkerJS_CloudFlare_ImageBed
不提供任何免费的技术支持、指导、问题解答请按GitHub标准用法进行issue等方式交互
请勿滥用本代码,违规使用后果自负,任何操作和后果均与本人无关
API接口均需要使用者自行解决本人不提供任何API接口服务
不得在中国大陆地区使用本代码
-->
2024-03-26 13:42:43 +08:00
<!-- 引入 Bootstrap CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.2/css/bootstrap.min.css">
<style>
.container {
margin-top: 50px;
}
</style>
</head>
<body>
2024-04-10 10:38:29 +08:00
<a href="https://github.com/BlueSkyXN/WorkerJS_CloudFlare_ImageBed" target="_blank" title="Visit GitHub Repository">
<img src="https://icons.iconarchive.com/icons/iconoir-team/iconoir/48/github-circle-icon.png" width="48" height="48">
</a>
2024-03-26 13:42:43 +08:00
<div class="container">
<h2>文件上传</h2>
<form id="upload-form">
<div class="form-group">
2024-03-26 14:03:46 +08:00
<label for="apiUrl">API 域名请包含完整http开头域名结尾不需要斜杠</label>
2024-03-26 13:42:43 +08:00
<input type="text" class="form-control" id="apiUrl" placeholder="输入 API 域名" required>
</div>
<div class="form-group">
<label for="fileInput">选择文件</label>
<input type="file" class="form-control-file" id="fileInput" required>
</div>
<div class="form-group">
<label for="apiSelect">选择接口</label>
<select class="form-control" id="apiSelect">
<option value="58img">api-58img</option>
<option value="tgphimg">api-tgph-official</option>
</select>
</div>
<button type="submit" class="btn btn-primary">上传</button>
</form>
<div id="result" class="mt-3" style="display: none;">
<label>返回的 URL</label>
<input type="text" class="form-control" id="resultUrl" readonly>
<button class="btn btn-success mt-2" onclick="copyUrl()">复制 URL</button>
</div>
</div>
<!-- 引入 jQuery 和 Bootstrap JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script>
document.getElementById('upload-form').addEventListener('submit', function(e) {
e.preventDefault();
const apiUrlInput = document.getElementById('apiUrl');
const fileInput = document.getElementById('fileInput');
const apiSelect = document.getElementById('apiSelect');
const formData = new FormData();
formData.append('image', fileInput.files[0]);
// 使用用户输入的 API 域名和选择的接口构造完整的 URL
const apiUrl = `${apiUrlInput.value}/upload/${apiSelect.value}`;
2024-03-26 13:49:22 +08:00
console.log('API URL:', apiUrl);
2024-03-26 14:03:46 +08:00
2024-03-26 13:42:43 +08:00
fetch(apiUrl, {
method: 'POST',
body: formData,
})
.then(response => response.text())
.then(data => {
document.getElementById('resultUrl').value = data;
document.getElementById('result').style.display = 'block';
})
.catch(error => console.error('Error:', error));
});
function copyUrl() {
const copyText = document.getElementById('resultUrl');
copyText.select();
copyText.setSelectionRange(0, 99999); // 对于移动设备
document.execCommand('copy');
alert('URL 已复制');
}
</script>
</body>
</html>