Fix Edit
This commit is contained in:
		
							parent
							
								
									c7bfdd4fc1
								
							
						
					
					
						commit
						3c72bf8ca0
					
				@ -78,6 +78,15 @@ public class Location {
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static String getLocationId(String name) {
 | 
			
		||||
        for (Location loc : LOCATIONS) {
 | 
			
		||||
            if (loc.getName().equals(name)) {
 | 
			
		||||
                return loc.getId();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String toString() {
 | 
			
		||||
        return "{ \"id\": " + id + ", \"name\": " + name + ", \"address\": " + address + ", \"number\": " + number + " }";
 | 
			
		||||
 | 
			
		||||
@ -3,6 +3,7 @@ package tech.nevets.vcardgen;
 | 
			
		||||
import com.google.gson.Gson;
 | 
			
		||||
import com.google.gson.JsonObject;
 | 
			
		||||
 | 
			
		||||
import javax.servlet.MultipartConfigElement;
 | 
			
		||||
import java.io.*;
 | 
			
		||||
 | 
			
		||||
import static spark.Spark.*;
 | 
			
		||||
@ -37,10 +38,11 @@ public class Main {
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
            post("/edit", (req, res) -> {
 | 
			
		||||
                req.attribute("org.eclipse.jetty.multipartConfig", new MultipartConfigElement("/temp"));
 | 
			
		||||
                res.status(200);
 | 
			
		||||
                res.type("application/json");
 | 
			
		||||
                res.header("Access-Control-Allow-Origin", "*");
 | 
			
		||||
                return VCard.getDataFromVCard(req.bodyAsBytes());
 | 
			
		||||
                return VCard.getDataFromVCard(req.raw().getPart("card").getInputStream());
 | 
			
		||||
            });
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -2,6 +2,9 @@ package tech.nevets.vcardgen;
 | 
			
		||||
 | 
			
		||||
import com.google.gson.Gson;
 | 
			
		||||
import com.google.gson.JsonObject;
 | 
			
		||||
import spark.Request;
 | 
			
		||||
import spark.Response;
 | 
			
		||||
import spark.Route;
 | 
			
		||||
 | 
			
		||||
import javax.imageio.*;
 | 
			
		||||
import javax.imageio.metadata.IIOMetadata;
 | 
			
		||||
@ -13,6 +16,7 @@ import java.awt.image.BufferedImage;
 | 
			
		||||
import java.io.ByteArrayInputStream;
 | 
			
		||||
import java.io.ByteArrayOutputStream;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.io.InputStream;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
@ -221,9 +225,9 @@ public class VCard {
 | 
			
		||||
        return C.getFontMetrics(font).stringWidth(text) < maxLength;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static String getDataFromVCard(byte[] rawImage) throws IOException {
 | 
			
		||||
    public static String getDataFromVCard(InputStream rawImage) throws IOException {
 | 
			
		||||
        ImageReader reader = ImageIO.getImageReadersByMIMEType("image/png").next();
 | 
			
		||||
        reader.setInput(ImageIO.createImageInputStream(new ByteArrayInputStream(rawImage)));
 | 
			
		||||
        reader.setInput(ImageIO.createImageInputStream(rawImage));
 | 
			
		||||
 | 
			
		||||
        IIOMetadata metadata = reader.getImageMetadata(0);
 | 
			
		||||
        IIOMetadataNode root = (IIOMetadataNode) metadata.getAsTree("javax_imageio_png_1.0");
 | 
			
		||||
@ -235,6 +239,12 @@ public class VCard {
 | 
			
		||||
            IIOMetadataNode textEntry = (IIOMetadataNode) text.item(i);
 | 
			
		||||
            String key = textEntry.getAttribute("keyword");
 | 
			
		||||
            String value = textEntry.getAttribute("value");
 | 
			
		||||
            if (key.equals("Address") || key.equals("SchoolNumber")) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
            if (key.equals("Location")) {
 | 
			
		||||
                value = Location.getLocationId(value);
 | 
			
		||||
            }
 | 
			
		||||
            keyValueMap.put(key, value);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user