mirror of
https://github.com/linuxserver/fleet.git
synced 2026-02-20 05:11:08 +08:00
Added legacy API controller for external API calls.
This commit is contained in:
parent
488fb67449
commit
7820617cd1
@ -9,7 +9,7 @@ repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
version = '2.0.0'
|
||||
version = '2.0.1'
|
||||
|
||||
sourceSets {
|
||||
|
||||
|
||||
60
src/main/java/io/linuxserver/fleet/v2/types/api/external/AllImagesExternalApiResponse.java
vendored
Normal file
60
src/main/java/io/linuxserver/fleet/v2/types/api/external/AllImagesExternalApiResponse.java
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2020 LinuxServer.io
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.linuxserver.fleet.v2.types.api.external;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class AllImagesExternalApiResponse {
|
||||
|
||||
private final Map<String, List<ExternalApiImage>> repositories;
|
||||
|
||||
public AllImagesExternalApiResponse() {
|
||||
this.repositories = new HashMap<>();
|
||||
}
|
||||
|
||||
public final void addImage(final String repositoryName,
|
||||
final String imageName,
|
||||
final long pullCount,
|
||||
final String version,
|
||||
final boolean stable) {
|
||||
|
||||
if (!repositories.containsKey(repositoryName)) {
|
||||
repositories.put(repositoryName, new ArrayList<>());
|
||||
}
|
||||
|
||||
repositories.get(repositoryName).add(new ExternalApiImage(imageName, pullCount, version, stable));
|
||||
}
|
||||
|
||||
public final long getTotalPullCount() {
|
||||
|
||||
long totalPullCount = 0L;
|
||||
for (List<ExternalApiImage> repositoryImages : repositories.values()) {
|
||||
for (ExternalApiImage image : repositoryImages) {
|
||||
totalPullCount += image.getPullCount();
|
||||
}
|
||||
}
|
||||
return totalPullCount;
|
||||
}
|
||||
|
||||
public final Map<String, List<ExternalApiImage>> getRepositories() {
|
||||
return repositories;
|
||||
}
|
||||
}
|
||||
49
src/main/java/io/linuxserver/fleet/v2/types/api/external/ExternalApiImage.java
vendored
Normal file
49
src/main/java/io/linuxserver/fleet/v2/types/api/external/ExternalApiImage.java
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2020 LinuxServer.io
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.linuxserver.fleet.v2.types.api.external;
|
||||
|
||||
public class ExternalApiImage {
|
||||
|
||||
private String name;
|
||||
private long pullCount;
|
||||
private String version;
|
||||
private boolean stable;
|
||||
|
||||
public ExternalApiImage(final String name, final long pullCount, final String version, final boolean stable) {
|
||||
this.name = name;
|
||||
this.pullCount = pullCount;
|
||||
this.version = version;
|
||||
this.stable = stable;
|
||||
}
|
||||
|
||||
public final String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public final long getPullCount() {
|
||||
return pullCount;
|
||||
}
|
||||
|
||||
public final String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public final boolean isStable() {
|
||||
return stable;
|
||||
}
|
||||
}
|
||||
41
src/main/java/io/linuxserver/fleet/v2/types/api/external/ExternalApiResponse.java
vendored
Normal file
41
src/main/java/io/linuxserver/fleet/v2/types/api/external/ExternalApiResponse.java
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2020 LinuxServer.io
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.linuxserver.fleet.v2.types.api.external;
|
||||
|
||||
public class ExternalApiResponse<T> {
|
||||
|
||||
private ApiStatus status;
|
||||
private T data;
|
||||
|
||||
public ExternalApiResponse(final ApiStatus status, final T data) {
|
||||
this.status = status;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public final ApiStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public final T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public enum ApiStatus {
|
||||
OK, Error
|
||||
}
|
||||
}
|
||||
@ -123,6 +123,9 @@ public class WebRouteController {
|
||||
put(apiController::runSchedule, roles(AppRole.Admin));
|
||||
});
|
||||
});
|
||||
|
||||
final LegacyExternalApiController externalApiController = new LegacyExternalApiController(app);
|
||||
get(Locations.Api.Images, externalApiController::fetchAllImages, roles(AppRole.Anyone));
|
||||
});
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(webInstance::stop));
|
||||
|
||||
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2019 LinuxServer.io
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.linuxserver.fleet.v2.web.routes;
|
||||
|
||||
import io.javalin.http.Context;
|
||||
import io.linuxserver.fleet.core.FleetAppController;
|
||||
import io.linuxserver.fleet.v2.service.AbstractAppService;
|
||||
import io.linuxserver.fleet.v2.types.Image;
|
||||
import io.linuxserver.fleet.v2.types.Repository;
|
||||
import io.linuxserver.fleet.v2.types.api.external.AllImagesExternalApiResponse;
|
||||
import io.linuxserver.fleet.v2.types.api.external.ExternalApiResponse;
|
||||
import io.linuxserver.fleet.v2.web.ApiException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LegacyExternalApiController extends AbstractAppService {
|
||||
|
||||
public LegacyExternalApiController(final FleetAppController controller) {
|
||||
super(controller);
|
||||
}
|
||||
|
||||
public final void fetchAllImages(final Context ctx) {
|
||||
|
||||
try {
|
||||
|
||||
final AllImagesExternalApiResponse responseData = new AllImagesExternalApiResponse();
|
||||
|
||||
final List<Repository> repositories = getController().getImageService().getAllShownRepositories();
|
||||
for (Repository repository : repositories) {
|
||||
|
||||
for (Image image : repository.getImages()) {
|
||||
|
||||
responseData.addImage(image.getRepositoryName(),
|
||||
image.getName(),
|
||||
image.getPullCount(),
|
||||
image.getLatestTag().getVersion(),
|
||||
image.isStable());
|
||||
}
|
||||
}
|
||||
|
||||
ctx.json(new ExternalApiResponse<>(ExternalApiResponse.ApiStatus.OK, responseData));
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new ApiException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
#Sun Apr 26 14:55:33 BST 2020
|
||||
app.build.date=2020-04-26T14\:55\:33
|
||||
#Sun Apr 26 20:17:59 BST 2020
|
||||
app.build.date=2020-04-26T20\:17\:59
|
||||
app.build.os=Linux
|
||||
app.build.user=josh
|
||||
app.version=2.0.0
|
||||
app.version=2.0.1
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user