mirror of
https://github.com/HangarMC/Hangar.git
synced 2024-11-21 01:21:54 +08:00
fix: make sure to generate s3 links with the right platform, if jars share platforms
This commit is contained in:
parent
43a8559640
commit
f04a253f58
@ -2,6 +2,7 @@ package io.papermc.hangar.db.dao.internal.table.versions.downloads;
|
||||
|
||||
import io.papermc.hangar.model.common.Platform;
|
||||
import io.papermc.hangar.model.db.versions.downloads.ProjectVersionDownloadTable;
|
||||
import io.papermc.hangar.model.db.versions.downloads.ProjectVersionDownloadTableWithPlatform;
|
||||
import io.papermc.hangar.model.db.versions.downloads.ProjectVersionPlatformDownloadTable;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@ -18,6 +19,7 @@ import org.jdbi.v3.sqlobject.statement.SqlUpdate;
|
||||
@JdbiRepository
|
||||
@RegisterConstructorMapper(ProjectVersionPlatformDownloadTable.class)
|
||||
@RegisterConstructorMapper(ProjectVersionDownloadTable.class)
|
||||
@RegisterConstructorMapper(ProjectVersionDownloadTableWithPlatform.class)
|
||||
public interface ProjectVersionDownloadsDAO {
|
||||
|
||||
@SqlBatch("INSERT INTO project_version_platform_downloads (version_id, platform, download_id) VALUES (:versionId, :platform, :downloadId)")
|
||||
@ -53,15 +55,21 @@ public interface ProjectVersionDownloadsDAO {
|
||||
@SqlQuery("SELECT * FROM project_version_downloads WHERE version_id = :versionId AND id = :downloadId")
|
||||
ProjectVersionDownloadTable getDownload(long versionId, long downloadId);
|
||||
|
||||
// we need to find the first version platform download for the given download ID, since only that is being uploaded to object storage
|
||||
// see comment in VersionFactory#processPendingVersionFile
|
||||
@SqlQuery("""
|
||||
SELECT pvd.*
|
||||
SELECT pvd.*,
|
||||
(SELECT platform
|
||||
FROM project_version_platform_downloads first
|
||||
WHERE first.download_id = pvpd.download_id
|
||||
LIMIT 1) AS platform
|
||||
FROM project_version_downloads pvd
|
||||
JOIN project_versions pv ON pv.id = pvd.version_id
|
||||
JOIN projects p ON pv.project_id = p.id
|
||||
JOIN project_version_platform_downloads pvpd ON pvd.id = pvpd.download_id
|
||||
WHERE p.id = :projectId
|
||||
AND pv.version_string = :versionString
|
||||
AND pvpd.platform = :platform
|
||||
WHERE pvpd.version_id = (SELECT id
|
||||
FROM project_versions pv
|
||||
WHERE pv.project_id = :projectId
|
||||
AND pv.version_string = :versionString)
|
||||
AND pvpd.platform = :platform;
|
||||
""")
|
||||
ProjectVersionDownloadTable getDownloadByPlatform(long projectId, String versionString, @EnumByOrdinal Platform platform);
|
||||
ProjectVersionDownloadTableWithPlatform getDownloadByPlatform(long projectId, String versionString, @EnumByOrdinal Platform platform);
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package io.papermc.hangar.model.db.versions.downloads;
|
||||
import io.papermc.hangar.model.db.Table;
|
||||
import org.jdbi.v3.core.mapper.reflect.JdbiConstructor;
|
||||
|
||||
public final class ProjectVersionDownloadTable extends Table {
|
||||
public class ProjectVersionDownloadTable extends Table {
|
||||
|
||||
private final long versionId;
|
||||
private final Long fileSize;
|
||||
|
@ -0,0 +1,17 @@
|
||||
package io.papermc.hangar.model.db.versions.downloads;
|
||||
|
||||
import io.papermc.hangar.model.common.Platform;
|
||||
|
||||
public class ProjectVersionDownloadTableWithPlatform extends ProjectVersionDownloadTable {
|
||||
|
||||
private final Platform platform;
|
||||
|
||||
public ProjectVersionDownloadTableWithPlatform(final long id, final long versionId, final Long fileSize, final String hash, final String fileName, final String externalUrl, final Platform platform) {
|
||||
super(id, versionId, fileSize, hash, fileName, externalUrl);
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
public Platform getPlatform() {
|
||||
return this.platform;
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ import io.papermc.hangar.model.api.project.version.PlatformVersionDownload;
|
||||
import io.papermc.hangar.model.common.Platform;
|
||||
import io.papermc.hangar.model.db.projects.ProjectTable;
|
||||
import io.papermc.hangar.model.db.versions.downloads.ProjectVersionDownloadTable;
|
||||
import io.papermc.hangar.model.db.versions.downloads.ProjectVersionDownloadTableWithPlatform;
|
||||
import io.papermc.hangar.model.db.versions.downloads.ProjectVersionPlatformDownloadTable;
|
||||
import io.papermc.hangar.service.internal.file.FileService;
|
||||
import io.papermc.hangar.service.internal.file.S3FileService;
|
||||
@ -69,7 +70,7 @@ public class DownloadService extends HangarComponent {
|
||||
throw new HangarApiException(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
final ProjectVersionDownloadTable download = this.downloadsDAO.getDownloadByPlatform(projectTable.getProjectId(), versionString, platform);
|
||||
final ProjectVersionDownloadTableWithPlatform download = this.downloadsDAO.getDownloadByPlatform(projectTable.getProjectId(), versionString, platform);
|
||||
if (download == null) {
|
||||
throw new HangarApiException(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
@ -78,7 +79,7 @@ public class DownloadService extends HangarComponent {
|
||||
if (StringUtils.hasText(download.getExternalUrl())) {
|
||||
return ResponseEntity.status(301).header("Location", download.getExternalUrl()).build();
|
||||
} else if (this.fileService instanceof S3FileService){
|
||||
return ResponseEntity.status(301).header("Location", this.fileService.getVersionDownloadUrl(ownerName, projectTable.getName(), versionString, platform, download.getFileName())).build();
|
||||
return ResponseEntity.status(301).header("Location", this.fileService.getVersionDownloadUrl(ownerName, projectTable.getName(), versionString, download.getPlatform(), download.getFileName())).build();
|
||||
} else {
|
||||
final String path = this.projectFiles.getVersionDir(ownerName, projectTable.getName(), versionString, platform, download.getFileName());
|
||||
if (!this.fileService.exists(path)) {
|
||||
|
Loading…
Reference in New Issue
Block a user