1
Fork 0
mirror of https://github.com/Quackster/Havana.git synced 2025-07-03 05:07:46 +00:00

Remove more unused code (fix compile error)

This commit is contained in:
Quackster 2022-09-03 15:49:48 +10:00
parent 13f5f83090
commit c4da58e113
4 changed files with 0 additions and 179 deletions

View file

@ -279,7 +279,6 @@ public class Routes {
// API
RouteManager.addRoute("/api/advertisement/get_img", AdvertisementController::getImg);
RouteManager.addRoute("/api/advertisement/get_url", AdvertisementController::getUrl);
RouteManager.addRoute("/photos/my_photos", PhotosController::viewphotos);
RouteManager.addRoute("/api/verify/get/*", VerifyController::get);
RouteManager.addRoute("/api/verify/clear/*", VerifyController::clear);

View file

@ -1,77 +0,0 @@
package org.alexdev.http.controllers.api;
import org.alexdev.duckhttpd.server.connection.WebConnection;
import org.alexdev.havana.game.item.Photo;
import org.alexdev.http.dao.CommunityDao;
import org.alexdev.http.util.HtmlUtil;
import org.alexdev.photorenderer.PhotoRenderer;
import org.alexdev.photorenderer.RenderOption;
import org.alexdev.photorenderer.palettes.GreyscalePalette;
import org.apache.commons.codec.binary.Base64;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class PhotosController {
public static void viewphotos(WebConnection webConnection) throws Exception {
if (!webConnection.session().contains("user.id")) {
webConnection.send("Please sign in");
return;
}
PhotoRenderer photoViewer = null;
var photos = CommunityDao.getPhotos(webConnection.session().getInt("user.id"));
StringBuilder stringBuilder = new StringBuilder();
var renderOption = RenderOption.GREYSCALE;
if (webConnection.get().contains("greyscale")) {
renderOption = RenderOption.GREYSCALE;
}
if (webConnection.get().contains("sepia")) {
renderOption = RenderOption.SEPIA;
}
if (renderOption != RenderOption.GREYSCALE) {
stringBuilder.append("<p>View images as greyscale? <a href=\"?greyscale\"\">View Greyscale</a></p>");
} else {
stringBuilder.append("<p>View images as original Sepia? <a href=\"?sepia\"\">View as Sepia</a></p>");
}
photoViewer = new PhotoRenderer(GreyscalePalette.getPalette(), renderOption);
//int i = 1;
for (Photo photo : photos) {
var src = photoViewer.createImage(photo.getData());
stringBuilder.append("<img src=\"data:image/png;base64," + HtmlUtil.encodeToString(src, "PNG") + "\"> ");
/*if (i % 6 == 0) {
stringBuilder.append("<br>");
}
i++;*/
}
/*i = 1;
for (Photo photo : photos) {
PhotoRenderer photoViewer = new PhotoRenderer();
var src = photoViewer.createImage(photo.getData(), photoViewer.getCachedPalette(), PhotoRenderOption.GREYSCALE);
stringBuilder.append("<img src=\"data:image/png;base64," + encodeToString(src, "PNG") + "\"> ");
if (i % 6 == 0) {
stringBuilder.append("<br>");
}
i++;
}*/
stringBuilder.append("<p><i>Made by Alex</i></p>");
webConnection.send(stringBuilder.toString());
}
}

View file

@ -2,13 +2,8 @@ package org.alexdev.http.dao;
import org.alexdev.havana.dao.Storage;
import org.alexdev.havana.dao.mysql.GroupDao;
import org.alexdev.havana.dao.mysql.ItemDao;
import org.alexdev.havana.game.groups.Group;
import org.alexdev.havana.game.item.Item;
import org.alexdev.havana.game.item.Photo;
import org.alexdev.http.game.CommunityPhoto;
import org.alexdev.http.game.groups.DiscussionTopic;
import org.alexdev.photorenderer.PhotoRenderer;
import java.sql.*;
import java.util.ArrayList;
@ -117,37 +112,4 @@ public class CommunityDao {
return discussionList;
}
public static List<Photo> getPhotos(int userId) throws SQLException {
List<Photo> photoList = new ArrayList<>();
Connection sqlConnection = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
try {
sqlConnection = Storage.getStorage().getConnection();
preparedStatement = Storage.getStorage().prepare("SELECT * FROM items_photos WHERE photo_user_id = ? ORDER BY timestamp DESC", sqlConnection);// (photo_id, photo_user_id, timestamp, photo_data, photo_checksum) VALUES (?, ?, ?, ?, ?)", sqlConnection);
preparedStatement.setInt(1, userId);
resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
Blob photoBlob = resultSet.getBlob("photo_data");
int blobLength = (int) photoBlob.length();
byte[] photoBlobBytes = photoBlob.getBytes(1, blobLength);
photoList.add(new Photo(resultSet.getInt("photo_id"), resultSet.getInt("photo_checksum"), photoBlobBytes, resultSet.getLong("timestamp")));
}
} catch (Exception e) {
Storage.logError(e);
throw e;
} finally {
Storage.closeSilently(preparedStatement);
Storage.closeSilently(sqlConnection);
Storage.closeSilently(resultSet);
}
return photoList;
}
}

View file

@ -1,63 +0,0 @@
package org.alexdev.http.game;
import org.alexdev.havana.game.item.Item;
import org.alexdev.havana.game.item.Photo;
import org.alexdev.http.util.HtmlUtil;
import org.alexdev.photorenderer.PhotoRenderer;
public class CommunityPhoto {
private final Photo photo;
private final PhotoRenderer photoViewer;
private final Item item;
private final long id;
public CommunityPhoto(Photo photo, PhotoRenderer photoViewer, Item item) {
this.id = photo.getId();
this.photo = photo;
this.photoViewer = photoViewer;
this.item = item;
}
public long getId() {
return id;
}
public String getDate() {
var customData = this.item.getCustomData();
if (customData.contains("\r")) {
return customData.substring(0, customData.indexOf("\r") - 3);
}
return null;
}
public String getDescription() {
var customData = this.item.getCustomData();
if (customData.contains("\r")) {
return customData.substring(customData.indexOf("\r") + 1);
}
return null;
}
public Photo getPhoto() {
return photo;
}
public String renderPhoto() {
try {
var src = this.photoViewer.createImage(photo.getData());
return HtmlUtil.encodeToString(src, "PNG");
} catch (Exception e) {
}
return null;
}
public PhotoRenderer getPhotoViewer() {
return photoViewer;
}
}