WorkerJS_CloudFlare_ImageBed/cloudflare-page/OneAPI-imgbed.html
2024-03-26 13:42:43 +08:00

82 lines
3.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>文件上传</title>
<!-- 引入 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>
<div class="container">
<h2>文件上传</h2>
<form id="upload-form">
<div class="form-group">
<label for="apiUrl">API 域名:</label>
<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}`;
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>