mirror of
https://github.com/BlueSkyXN/WorkerJS_CloudFlare_ImageBed.git
synced 2024-11-16 03:32:26 +08:00
83 lines
3.3 KiB
HTML
83 lines
3.3 KiB
HTML
<!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 域名(请包含完整http开头,域名结尾不需要斜杠):</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}`;
|
||
console.log('API URL:', apiUrl);
|
||
|
||
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>
|