Skip to content

Commit

Permalink
安全更新
Browse files Browse the repository at this point in the history
  • Loading branch information
power721 committed Dec 26, 2023
1 parent 4479741 commit d2ab2e3
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@ private void fixId(List<Subscription> list) {
}
}

public String getToken(String apiKey) {
String key = settingRepository.findById("api_key").map(Setting::getValue).orElse("");
if (key.equals(apiKey)) {
return token;
} else {
return "";
}
}

public String getToken() {
return token;
}
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/cn/har01d/alist_tvbox/web/TvBoxController.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,22 @@ public List<String> getProfiles() {
}

@GetMapping("/token")
public String getToken2(HttpServletRequest request) {
String apiKey = request.getHeader("X-API-KEY");
return subscriptionService.getToken(apiKey);
}

@GetMapping("/api/token")
public String getToken() {
return subscriptionService.getToken();
}

@PostMapping("/token")
@PostMapping("/api/token")
public String createToken(@RequestBody TokenDto dto) {
return subscriptionService.createToken(dto);
}

@DeleteMapping("/token")
@DeleteMapping("/api/token")
public void deleteToken() {
subscriptionService.deleteToken();
}
Expand Down
4 changes: 2 additions & 2 deletions web-ui/src/views/ConfigView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,12 @@ const formatTime = (value: string | number) => {
const updateToken = () => {
if (form.value.enabledToken) {
axios.post('/token', {token: form.value.token}).then(({data}) => {
axios.post('/api/token', {token: form.value.token}).then(({data}) => {
form.value.token = data
ElMessage.success('成功开启安全订阅')
})
} else {
axios.delete('/token').then(() => {
axios.delete('/api/token').then(() => {
form.value.token = ''
ElMessage.info('成功关闭安全订阅')
})
Expand Down
2 changes: 1 addition & 1 deletion web-ui/src/views/SearchView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const search = function () {
}
onMounted(() => {
axios.get('/token').then(({data}) => {
axios.get('/api/token').then(({data}) => {
token.value = data ? '/' + data : ''
})
})
Expand Down
2 changes: 1 addition & 1 deletion web-ui/src/views/SitesView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ const handleExceed: UploadProps['onExceed'] = (files: File[]) => {
onMounted(() => {
load()
axios.get('/token').then(({data}) => {
axios.get('/api/token').then(({data}) => {
token.value = data ? '/' + data : ''
})
})
Expand Down
2 changes: 1 addition & 1 deletion web-ui/src/views/SubView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ watch(
)
onMounted(async () => {
token.value = await axios.get('/token').then(({data}) => {
token.value = await axios.get('/api/token').then(({data}) => {
return data ? '/' + data : ''
})
id.value = route.params.id as string
Expand Down
2 changes: 1 addition & 1 deletion web-ui/src/views/SubscriptionsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ const load = () => {
}
onMounted(() => {
axios.get('/token').then(({data}) => {
axios.get('/api/token').then(({data}) => {
token.value = data ? '/' + data : ''
load()
})
Expand Down
2 changes: 1 addition & 1 deletion web-ui/src/views/VodView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const load = function () {
}
onMounted(async () => {
token.value = await axios.get('/token').then(({data}) => {
token.value = await axios.get('/api/token').then(({data}) => {
return data ? '/' + data : ''
})
url.value = currentUrl + getPath(type.value) + token.value
Expand Down

0 comments on commit d2ab2e3

Please sign in to comment.