Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the repository URL #3192

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
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
25 changes: 22 additions & 3 deletions src/main/java/com/faforever/client/mod/ModUploadTask.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
package com.faforever.client.mod;

import com.faforever.client.api.FafApiAccessor;
import com.faforever.client.domain.api.ModVersion;
import com.faforever.client.i18n.I18n;
import com.faforever.client.preferences.DataPrefs;
import com.faforever.client.task.CompletableTask;
import com.faforever.client.task.ResourceLocks;
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.HashMap;
import java.util.Locale;
import java.util.Map;

Expand All @@ -29,15 +33,20 @@
@Slf4j
public class ModUploadTask extends CompletableTask<Void> {

private final ModService modService;
private final FafApiAccessor fafApiAccessor;
private final I18n i18n;
private final DataPrefs dataPrefs;

private Path modPath;

@Setter
private URL repositoryURL;

@Autowired
public ModUploadTask(FafApiAccessor fafApiAccessor, I18n i18n, DataPrefs dataPrefs) {
public ModUploadTask(ModService modService, FafApiAccessor fafApiAccessor, I18n i18n, DataPrefs dataPrefs) {
super(Priority.HIGH);
this.modService = modService;
this.dataPrefs = dataPrefs;
this.fafApiAccessor = fafApiAccessor;
this.i18n = i18n;
Expand Down Expand Up @@ -69,10 +78,20 @@ protected Void call() throws Exception {
.zip();
}

// retrieve information from the mod_info.lua to send to the API

ModVersion modVersionInfo = modService.extractModInfo(modPath);
URL repositoryURL = modVersionInfo.mod().repositoryURL();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is shadowing the field repositoryUrl now. So the field should be removed or this should set the field if it is null.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Processed in: 57ff0b3


log.debug("Uploading mod `{}` as `{}`", modPath, tmpFile);
updateTitle(i18n.get("modVault.upload.uploading"));

return fafApiAccessor.uploadFile("/mods/upload", tmpFile, byteListener, Map.of()).block();
HashMap<String, String> parameters = new HashMap<>();
if (repositoryURL != null) {
parameters.put("repositoryUrl", repositoryURL.toString());
}

return fafApiAccessor.uploadFile("/mods/upload", tmpFile, byteListener, Map.of("metadata", parameters)).block();
} finally {
Files.delete(tmpFile);
ResourceLocks.freeUploadLock();
Expand All @@ -82,4 +101,4 @@ protected Void call() throws Exception {
public void setModPath(Path modPath) {
this.modPath = modPath;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void setUp() throws Exception {
return null;
}).when(executorService).execute(any());

modUploadTask = new ModUploadTask(fafApiAccessor, i18n, dataPrefs) {
modUploadTask = new ModUploadTask(modService, fafApiAccessor, i18n, dataPrefs) {
@Override
protected Void call() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ public class ModUploadTaskTest extends PlatformTest {
@TempDir
public Path tempDirectory;


private ModUploadTask instance;

@Mock
private ModService modService;

@Mock
private FafApiAccessor fafApiAccessor;
@Mock
Expand All @@ -37,7 +41,7 @@ public class ModUploadTaskTest extends PlatformTest {

@BeforeEach
public void setUp() throws Exception {
instance = new ModUploadTask(fafApiAccessor, i18n, dataPrefs);
instance = new ModUploadTask(modService, fafApiAccessor, i18n, dataPrefs);
dataPrefs.setBaseDataDirectory(tempDirectory);

Files.createDirectories(dataPrefs.getCacheDirectory());
Expand Down
Loading