Skip to content

Commit

Permalink
Pass the repository URL to the API
Browse files Browse the repository at this point in the history
  • Loading branch information
Garanas committed Jun 2, 2024
1 parent 74e9dae commit 410adbf
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions .idea/runConfigurations/Main.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ dependencies {
implementation("io.projectreactor.addons:reactor-extra")
implementation("io.projectreactor:reactor-tools")

def commonsVersion = "1013d75fc9"
def commonsVersion = "9c1978d235"

implementation("com.github.FAForever.faf-java-commons:faf-commons-data:${commonsVersion}") {
exclude module: 'guava'
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/com/faforever/client/domain/api/Mod.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

import com.faforever.client.domain.server.PlayerInfo;

import java.net.URL;

public record Mod(
Integer id,
String displayName,
boolean recommended, String author, PlayerInfo uploader, ReviewsSummary reviewsSummary
URL repositoryURL,
boolean recommended,
String author,
PlayerInfo uploader,
ReviewsSummary reviewsSummary
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ public record ModVersion(
ComparableVersion version,
URL thumbnailUrl,
URL downloadUrl,
ModType modType, boolean ranked, boolean hidden, Mod mod,
ModType modType,
boolean ranked,
boolean hidden,
Mod mod,
OffsetDateTime createTime,
OffsetDateTime updateTime
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public interface ModMapper {
@Mapping(target = "modType", source = "modInfo.uiOnly")
@Mapping(target = "mod", expression = "java(new ModBean())")
@Mapping(target = "mod.displayName", source = "modInfo.name")
@Mapping(target = "mod.repositoryURL", source = "modInfo.url")
ModVersion map(com.faforever.commons.mod.Mod modInfo, Path basePath);

default ModType mapModType(boolean isUIOnly) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/faforever/client/mod/ModService.java
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ public CompletableTask<Void> uploadMod(Path modPath) {
ModUploadTask modUploadTask = modUploadTaskFactory.getObject();
modUploadTask.setModPath(modPath);

// retrieve information from the mod_info.lua to send to the API
ModVersion modVersion = extractModInfo(modPath);
modUploadTask.setRepositoryURL(modVersion.mod().repositoryURL());

return taskService.submitTask(modUploadTask);
}

Expand Down
9 changes: 7 additions & 2 deletions src/main/java/com/faforever/client/mod/ModUploadTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
import com.faforever.client.util.Validator;
import com.faforever.commons.io.ByteCountListener;
import com.faforever.commons.io.Zipper;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.io.OutputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Locale;
Expand All @@ -35,6 +37,9 @@ public class ModUploadTask extends CompletableTask<Void> {

private Path modPath;

@Setter
private URL repositoryURL;

@Autowired
public ModUploadTask(FafApiAccessor fafApiAccessor, I18n i18n, DataPrefs dataPrefs) {
super(Priority.HIGH);
Expand Down Expand Up @@ -72,7 +77,7 @@ protected Void call() throws Exception {
log.debug("Uploading mod `{}` as `{}`", modPath, tmpFile);
updateTitle(i18n.get("modVault.upload.uploading"));

return fafApiAccessor.uploadFile("/mods/upload", tmpFile, byteListener, Map.of()).block();
return fafApiAccessor.uploadFile("/mods/upload", tmpFile, byteListener, Map.of("metadata", Map.of("repositoryUrl", repositoryURL))).block();
} finally {
Files.delete(tmpFile);
ResourceLocks.freeUploadLock();
Expand All @@ -82,4 +87,4 @@ protected Void call() throws Exception {
public void setModPath(Path modPath) {
this.modPath = modPath;
}
}
}

0 comments on commit 410adbf

Please sign in to comment.