diff --git a/src/main/java/org/ntlab/acanthus_server/resources/accounts/FollowsRest.java b/src/main/java/org/ntlab/acanthus_server/resources/accounts/FollowsRest.java index a33b961..5370bb1 100644 --- a/src/main/java/org/ntlab/acanthus_server/resources/accounts/FollowsRest.java +++ b/src/main/java/org/ntlab/acanthus_server/resources/accounts/FollowsRest.java @@ -72,7 +72,7 @@ @Path("/{uid}/follows") @DELETE @Produces(MediaType.APPLICATION_JSON) - public void releaseFollows(@PathParam("uid") Integer uid, @FormParam("token") String token, @FormParam("followUid") Integer followUid){ + public String releaseFollows(@PathParam("uid") Integer uid, @QueryParam("token") String token, @QueryParam("followUid") Integer followUid){ var account = accounts.getAccountByUid(uid); var followAccount = account.getFollowsHashMap().get(followUid);//フォロー内アカウント参照 @@ -81,7 +81,7 @@ account.getFollowsHashMap().remove(followUid); followAccount.getFollowersHashMap().remove(uid); - //return "フォローを解除しました"; + return "フォローを解除しました"; }else { var response = Response.status(401).entity("フォローしているユーザーでないかユーザーIDが間違っています"); throw new WebApplicationException(response.build()); diff --git a/src/main/java/org/ntlab/acanthus_server/resources/gallery/StrokesRest.java b/src/main/java/org/ntlab/acanthus_server/resources/gallery/StrokesRest.java index 52a8e4d..6a7f4ef 100644 --- a/src/main/java/org/ntlab/acanthus_server/resources/gallery/StrokesRest.java +++ b/src/main/java/org/ntlab/acanthus_server/resources/gallery/StrokesRest.java @@ -1,24 +1,36 @@ package org.ntlab.acanthus_server.resources.gallery; import org.ntlab.acanthus_server.entities.*; +import org.ntlab.acanthus_server.entities.Stroke; import org.ntlab.acanthus_server.models.Gallery; +import org.ntlab.acanthus_server.utils.Base64Decode; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Component; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.SortedSet; +import java.io.IOException; +import java.util.*; // _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ // @Component @Path("/gallery") -public class StrokesRest { +public class StrokesRest implements ApplicationContextAware { private final Gallery gallery = Gallery.getInstance(); - private int srstrokeSize=0; - private int srstrokeNo=0; + private int srstrokeSize = 0; + private int srstrokeNo = 0; + + private ApplicationContext applicationContext; + + + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.applicationContext = applicationContext; + } + + // _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ // 1ページの1レイヤーに置ける筆跡情報を全て取得します // 成功時のレスポンス:strokeNo{pen, color, thickness, potions{x, y}} @@ -55,8 +67,8 @@ @POST @Produces(MediaType.APPLICATION_JSON) public String addStrokes(@PathParam("aid") Integer aid, @PathParam("pid") Integer pid, @PathParam("layerNo") Integer layerNo, - @FormParam("uid") Integer uid, @FormParam("strokeNo") Integer strokeNo, @FormParam("uidToken") String uidToken, @FormParam("pen") Integer pen, - @FormParam("color") Integer color, @FormParam("thick") Integer thick) { + @FormParam("uid") Integer uid, @FormParam("strokeNo") Integer strokeNo, @FormParam("uidToken") String uidToken, @FormParam("pen") Integer pen, + @FormParam("color") Integer color, @FormParam("thick") Integer thick) { var pages = gallery.getAnimationByAid(aid).getPages(); var strokes = new ArrayList(); @@ -81,10 +93,56 @@ @Path("/{aid}/pageMap/{pid}/image") @GET @Produces(MediaType.APPLICATION_JSON) - public String getLayers(@PathParam("aid") Integer aid, @PathParam("pid") Integer pid) { - return "http://nitta-lab-www.is.konan-u.ac.jp/gallery/" + aid + "/" + pid + "/a" + aid + "p" + pid + ".png"; + public HashMap getPageUrls(@PathParam("aid") Integer aid, @PathParam("pid") Integer pid) { + Animation animation = gallery.getAnimationByAid(aid); + ArrayList pages = animation.getPages(); + HashMap pageUrl = new HashMap<>(); + + for (Page p : pages) { + String url = "http://nitta-lab-www.is.konan-u.ac.jp/gallery/" + aid + "/" + p.getPid() + "/a" + aid + "p" + p.getPid() + ".png"; + pageUrl.put(p.getPageNo(), url); + } + + return pageUrl; } + + // _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ + // スクショで撮った画像をサーバ内の指定フォルダーにおく + // @PathParam Integer aid 作品のID + // @PathParam Integer pid ページのID + // @FormParam String image Base64 + @Path("/{aid}/pageMap/{pid}/image") + @POST + @Produces(MediaType.APPLICATION_JSON) + public String addImage(@PathParam("aid") Integer aid, @PathParam("pid") Integer pid, @FormParam("image") String image) { + + + String vid = "a" + aid.toString() + pid.toString(); +// String url = "http://nitta-lab-www.is.konan-u.ac.jp/nitta-lab-www/webapps/"; + + String path1 = ""; + try { +// path1 = applicationContext.getResource("http:").getFile().getAbsolutePath() + "/apache-tomcat-9.0.10/webapps"; + path1 = applicationContext.getResource("file:").getFile().getAbsolutePath() + "/apache-tomcat-9.0.10/webapps"; +// String url = "http://nitta-lab-www.is.konan-u.ac.jp" + path1; + Base64Decode.saveAsFile(aid, pid, path1, image); + + } catch (IOException e) { + e.printStackTrace(); + throw new WebApplicationException(500); + } + + + +/* ArrayList categories = (ArrayList) category; + ScreenImage v = screenimage.createScreenImage(aid, pid, vid, url, categories); + return v;*/ + + return path1; + } + + // _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ // レイヤーごとのstrokeをすべて消去 // @PathParam Integer aid 作品のID @@ -187,7 +245,7 @@ @POST @Produces(MediaType.APPLICATION_JSON) public String addPosition(@FormParam("positionNo") Integer positionNo, @PathParam("aid") Integer aid, @PathParam("pid") Integer pid, @PathParam("strokeNo") Integer strokeNo, - @PathParam("layerNo") Integer layerNo, @FormParam("x") Float x, @FormParam("y") Float y) { + @PathParam("layerNo") Integer layerNo, @FormParam("x") Float x, @FormParam("y") Float y) { var pages = gallery.getAnimationByAid(aid).getPages(); var strokes = new ArrayList(); @@ -198,19 +256,18 @@ var position = new Position(); position.setXY(positionNo, x, y); - if(srstrokeNo==strokeNo){ + if (srstrokeNo == strokeNo) { strokes.get(srstrokeSize).addPosition(position); - }else { - for(int i = 0; i < strokes.size(); i++){ - if(strokes.get(i).getStrokeNo()==strokeNo) - { - srstrokeNo=strokes.get(i).getStrokeNo(); - srstrokeSize=i; + } else { + for (int i = 0; i < strokes.size(); i++) { + if (strokes.get(i).getStrokeNo() == strokeNo) { + srstrokeNo = strokes.get(i).getStrokeNo(); + srstrokeSize = i; strokes.get(i).addPosition(position); } } } - // strokes.get(strokeNo).addPosition(position); // 呼び出したstrokesに座標を追加する + // strokes.get(strokeNo).addPosition(position); // 呼び出したstrokesに座標を追加する // if(animation != null) { ////// this.Position.setXY(x, y); ////// this.positions.add(this.Position); diff --git a/src/main/java/org/ntlab/acanthus_server/utils/Base64Decode.java b/src/main/java/org/ntlab/acanthus_server/utils/Base64Decode.java new file mode 100644 index 0000000..193895c --- /dev/null +++ b/src/main/java/org/ntlab/acanthus_server/utils/Base64Decode.java @@ -0,0 +1,38 @@ +package org.ntlab.acanthus_server.utils; + +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Base64; + +public class Base64Decode { + public static String saveAsFile(Integer aid ,Integer pid ,String path1 ,String enimage) throws IOException { + + + //デコードを行う + byte[] dedata = Base64.getDecoder().decode(enimage); + + //ファイルがないときは作成する + String fileName = "a" + aid.toString() + "p" + pid.toString() + ".png"; + String path2 = "/gallery/"+ aid.toString() + pid.toString(); + String path = path1 + path2 + "/" + fileName; + + System.out.println(path.toString()); + + File file = new File(path); + file.getParentFile().mkdirs(); + file.createNewFile(); + + //ファイルに画像データを書き込む + FileOutputStream file1 = new FileOutputStream(file, false); + BufferedOutputStream bf = new BufferedOutputStream(file1); + bf.write(dedata, 0, dedata.length); + + //ファイルを閉じる + bf.close(); + + //セーブしたファイルの相対パスを文字列として返す + return path2; + } +}