discourse tweaks

This commit is contained in:
Jake Potrebic 2021-05-14 15:39:03 -07:00
parent b08d4413a3
commit a566802b75
No known key found for this signature in database
GPG Key ID: 7C58557EC9C421F8
6 changed files with 17 additions and 4 deletions

View File

@ -137,7 +137,14 @@ hangar:
- "github.com"
discourse:
enabled: true
enabled: false
url: "http://localhost:80/"
admin-user: "admin"
api-key: "4657cc5e3096e505903b59eb789005eb3f207d0c61f62212bf929268740c1585"
jobs:
check-interval: 30s
unknown-error-timeout: 15
status-error-timeout: 5
not-available-timeout: 2
max-concurrent-jobs: 32

View File

@ -165,7 +165,7 @@ export default class ProjectPage extends HangarComponent {
const tabs = [] as Tab[];
tabs.push({ title: this.$t('project.tabs.docs'), icon: 'mdi-book', link: this.slug, external: false, exact: true });
tabs.push({ title: this.$t('project.tabs.versions'), icon: 'mdi-download', link: this.slug + '/versions', external: false });
if (this.project.settings.forumSync) {
if (this.project.settings.forumSync && this.project.postId) {
tabs.push({ title: this.$t('project.tabs.discuss'), icon: 'mdi-account-group', link: this.slug + '/discuss', external: false });
}
if (this.$perms.canEditSubjectSettings) {

View File

@ -1,5 +1,6 @@
package io.papermc.hangar.controller.internal;
import io.papermc.hangar.exceptions.HangarApiException;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
@ -27,6 +28,9 @@ public class DiscourseController extends HangarComponent {
@PostMapping("/{projectId}/comment")
@ResponseBody
public String createPost(@PathVariable("projectId") long projectId, @RequestBody Map<String, String> content) {
if (!config.discourse.isEnabled()) {
throw new HangarApiException("Discourse is NOT enabled!");
}
jobService.save(new PostDiscourseReplyJob(projectId, getHangarPrincipal().getName(), content.get("content")));
return "dum";
}

View File

@ -40,7 +40,7 @@ public class DiscourseError extends RuntimeException {
public static class NotAvailableError extends DiscourseError {
@Override
public String getMessage() {
return "Discourse ins't available";
return "Discourse isn't available";
}
}

View File

@ -60,6 +60,7 @@ public class JobService extends HangarComponent {
}
public void checkAndProcess() {
if (!config.discourse.isEnabled()) { return; }
long awaitingJobs = jobsDAO.countAwaitingJobs();
logger.debug("Found {} awaiting jobs", awaitingJobs);
if (awaitingJobs > 0) {
@ -75,6 +76,7 @@ public class JobService extends HangarComponent {
}
public void save(Job job) {
if (!config.discourse.isEnabled()) { return; }
jobsDAO.save(job.toTable());
}

View File

@ -17,7 +17,7 @@ public class JobUpdateTask {
this.service = service;
}
@Scheduled(fixedRateString = "${hangar.jobs.check-interval}", initialDelayString = "${hangar.jobs.check-interval}")
@Scheduled(fixedRateString = "#{@hangarConfig.jobs.checkInterval.toMillis()}", initialDelayString = "#{@hangarConfig.jobs.checkInterval.toMillis()}")
public void checkAndProcess() {
service.checkAndProcess();
}