Add: clear
This commit is contained in:
@@ -2,10 +2,11 @@ import {
|
|||||||
deleteTimeRange,
|
deleteTimeRange,
|
||||||
getLimit,
|
getLimit,
|
||||||
authenticate,
|
authenticate,
|
||||||
|
updateUsername,
|
||||||
updateUsernameWithLimit,
|
updateUsernameWithLimit,
|
||||||
} from "../../../../libs/db";
|
} from "../../../../libs/db";
|
||||||
|
|
||||||
import { addAPIQPS } from '../../../../libs/stats';
|
import { addAPIQPS } from "../../../../libs/stats";
|
||||||
|
|
||||||
export default function handler(req, res) {
|
export default function handler(req, res) {
|
||||||
addAPIQPS();
|
addAPIQPS();
|
||||||
@@ -43,6 +44,16 @@ export default function handler(req, res) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// admin update username
|
||||||
|
const { token } = req.body;
|
||||||
|
if (authenticate(token)) {
|
||||||
|
updateUsername.run(username, id);
|
||||||
|
res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const limit = getLimit();
|
const limit = getLimit();
|
||||||
updateUsernameWithLimit(username, id, limit);
|
updateUsernameWithLimit(username, id, limit);
|
||||||
|
|||||||
@@ -34,6 +34,29 @@ export default function Time(props) {
|
|||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
const updateUsernameByAdmin = (id, username) => {
|
||||||
|
fetch(`${prefix}/api/time/ranges/${id}`, {
|
||||||
|
method: "PUT",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
username,
|
||||||
|
token,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
.then((res) => res.json())
|
||||||
|
.then((res) => {
|
||||||
|
if (res.error) {
|
||||||
|
setSnackbarError(true);
|
||||||
|
setSnackbarErrorMessage(res.error);
|
||||||
|
} else {
|
||||||
|
setSnackbarSuccess(true);
|
||||||
|
refreshRanges();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const getStats = () => {
|
const getStats = () => {
|
||||||
fetch(`${prefix}/api/stats`, {
|
fetch(`${prefix}/api/stats`, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
@@ -330,16 +353,21 @@ export default function Time(props) {
|
|||||||
{range.username ? range.username : "抢!"}
|
{range.username ? range.username : "抢!"}
|
||||||
</Button>
|
</Button>
|
||||||
{isAdmin() && (
|
{isAdmin() && (
|
||||||
<Button
|
<>
|
||||||
sx={{
|
<Button
|
||||||
userSelect: "none",
|
variant="contained"
|
||||||
}}
|
onClick={() => updateUsernameByAdmin(range.id, "")}
|
||||||
variant="contained"
|
>
|
||||||
color="secondary"
|
清空
|
||||||
onClick={() => deleteRange(range.id)}
|
</Button>
|
||||||
>
|
<Button
|
||||||
删除
|
variant="contained"
|
||||||
</Button>
|
color="secondary"
|
||||||
|
onClick={() => deleteRange(range.id)}
|
||||||
|
>
|
||||||
|
删除
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
|
|||||||
Reference in New Issue
Block a user