Fixed image overwriting for export

This commit is contained in:
Rsl1122 2019-09-01 19:05:07 +03:00
parent b67534af20
commit dd57dff4ae
4 changed files with 18 additions and 17 deletions

View File

@ -17,7 +17,6 @@
package com.djrapitops.plan.delivery.export;
import com.djrapitops.plan.TaskSystem;
import com.djrapitops.plan.delivery.upkeep.ExportTask;
import com.djrapitops.plan.identification.Server;
import com.djrapitops.plan.settings.config.PlanConfig;
import com.djrapitops.plan.settings.config.paths.ExportSettings;
@ -68,9 +67,17 @@ public class ExportScheduler {
public void scheduleExport() {
scheduleServerPageExport();
schedulePlayersPageExport();
}
public void scheduleServerPageExport() {
private void schedulePlayersPageExport() {
long period = TimeAmount.toTicks(config.get(ExportSettings.EXPORT_PERIOD), TimeUnit.MILLISECONDS);
taskSystem.registerTask("Players page export",
new ExportTask(exporter, Exporter::exportPlayersPage, logger, errorHandler)
).runTaskTimerAsynchronously(0L, period);
}
private void scheduleServerPageExport() {
if (!config.get(ExportSettings.SERVER_PAGE)) return;
Collection<Server> servers = dbSystem.getDatabase().query(ServerQueries.fetchPlanServerInformationCollection());
@ -81,15 +88,11 @@ public class ExportScheduler {
long offset = period / serverCount;
Optional<Server> proxy = servers.stream().filter(Server::isProxy).findFirst();
proxy.ifPresent(server -> taskSystem.registerTask("Server export",
new ExportTask(exporter, exporter -> exporter.exportServerPage(server), logger, errorHandler))
proxy.ifPresent(mainServer -> taskSystem.registerTask("Network export",
new ExportTask(exporter, exporter -> exporter.exportServerPage(mainServer), logger, errorHandler))
.runTaskTimerAsynchronously(0L, period)
);
taskSystem.registerTask("Players page export",
new ExportTask(exporter, Exporter::exportPlayersPage, logger, errorHandler)
).runTaskTimerAsynchronously(0L, period);
int offsetMultiplier = proxy.isPresent() ? 1 : 0; // Delay first server export if on a network.
for (Server server : servers) {
taskSystem.registerTask("Server export",

View File

@ -14,9 +14,8 @@
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan.delivery.upkeep;
package com.djrapitops.plan.delivery.export;
import com.djrapitops.plan.delivery.export.Exporter;
import com.djrapitops.plan.exceptions.ExportException;
import com.djrapitops.plan.utilities.java.ThrowingConsumer;
import com.djrapitops.plugin.logging.L;

View File

@ -107,7 +107,7 @@ public class Exporter {
return true;
} catch (IOException | NotFoundException | ParseException e) {
failedServers.add(serverUUID);
throw new ExportException("Failed to export server: " + server.getIdentifiableName() + " (Attempts disabled until next reload), " + e.getMessage(), e);
throw new ExportException("Failed to export server: " + server.getIdentifiableName() + " (Attempts disabled until next reload), " + e.toString(), e);
}
}
@ -127,7 +127,7 @@ public class Exporter {
playerPageExporter.export(toDirectory, playerUUID, playerName);
return true;
} catch (IOException | NotFoundException | ParseException e) {
throw new ExportException("Failed to export player: " + playerName + ", " + e.getMessage(), e);
throw new ExportException("Failed to export player: " + playerName + ", " + e.toString(), e);
}
}
@ -139,7 +139,7 @@ public class Exporter {
playersPageExporter.export(toDirectory);
return true;
} catch (IOException | NotFoundException | ParseException e) {
throw new ExportException("Failed to export players page, " + e.getMessage(), e);
throw new ExportException("Failed to export players page, " + e.toString(), e);
}
}
@ -159,7 +159,7 @@ public class Exporter {
playerJSONExporter.export(toDirectory, playerUUID, playerName);
return true;
} catch (IOException e) {
throw new ExportException("Failed to export player: " + playerName + ", " + e.getMessage(), e);
throw new ExportException("Failed to export player: " + playerName + ", " + e.toString(), e);
}
}
}

View File

@ -59,11 +59,10 @@ abstract class FileExporter {
void export(Path to, Resource resource) throws IOException {
Files.createDirectories(to.getParent());
if (Files.exists(to)) Files.delete(to);
Files.createFile(to);
try (
InputStream in = resource.asInputStream();
OutputStream out = Files.newOutputStream(to)
OutputStream out = Files.newOutputStream(to, StandardOpenOption.CREATE)
) {
copy(in, out);
}