-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_upload_with_team.html
More file actions
89 lines (77 loc) · 2.92 KB
/
test_upload_with_team.html
File metadata and controls
89 lines (77 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<!DOCTYPE html>
<html>
<head>
<title>Test Upload with Team</title>
</head>
<body>
<h1>Test File Upload with Team</h1>
<p>This simulates the frontend upload process with team selection.</p>
<div>
<label>Select Team:</label>
<select id="teamSelect">
<option value="engineering">Engineering</option>
<option value="marketing">Marketing</option>
<option value="sales">Sales</option>
<option value="support">Support</option>
<option value="research">Research</option>
</select>
</div>
<div>
<label>Select File:</label>
<input type="file" id="fileInput" accept=".txt,.pdf,.docx">
</div>
<button onclick="testUpload()">Upload File</button>
<div id="result"></div>
<script>
// Set team in localStorage (simulating frontend behavior)
localStorage.setItem('currentTeam', 'engineering');
async function testUpload() {
const fileInput = document.getElementById('fileInput');
const teamSelect = document.getElementById('teamSelect');
const file = fileInput.files[0];
const team = teamSelect.value;
if (!file) {
alert('Please select a file');
return;
}
// Update localStorage with selected team
localStorage.setItem('currentTeam', team);
const text = await extractTextFromFile(file);
const uploadData = {
name: file.name,
content: text,
type: file.type,
department: team,
author: team.charAt(0).toUpperCase() + team.slice(1) + ' Team',
tags: ['test', 'upload']
};
try {
const response = await fetch('http://localhost:8001/api/documents', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(uploadData)
});
const result = await response.json();
document.getElementById('result').innerHTML =
'<h3>Upload Result:</h3><pre>' + JSON.stringify(result, null, 2) + '</pre>';
} catch (error) {
document.getElementById('result').innerHTML =
'<h3>Error:</h3><pre>' + error.message + '</pre>';
}
}
function extractTextFromFile(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = (e) => {
const text = e.target?.result;
resolve(text);
};
reader.onerror = reject;
reader.readAsText(file);
});
}
</script>
</body>
</html>