Skip to content

Commit 5ec6017

Browse files
committed
Update Node API.
1 parent a374eeb commit 5ec6017

14 files changed

Lines changed: 422 additions & 4 deletions

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>org.moera</groupId>
77
<artifactId>moeralib</artifactId>
8-
<version>0.18.2</version>
8+
<version>0.18.3</version>
99

1010
<name>moeralib</name>
1111
<description>Java library to interact with Moera decentralized social network</description>

src/main/java/org/moera/lib/node/MoeraNode.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,15 +1309,18 @@ public PrivateMediaFileInfo uploadPrivateMedia(
13091309
* size, but the best in quality variant of the media, according to the width provided
13101310
* @param download if <code>true</code>, the node will add <code>Content-Disposition: attachment</code> header to
13111311
* the output
1312+
* @param ignoremalware if <code>true</code>, the node will ignore malware detection and return the media file;
1313+
* only admin may use this option
13121314
* @param responseConsumer consumer of the data received
13131315
*/
13141316
public void getPrivateMedia(
1315-
String id, Integer width, Boolean download, ResponseConsumer responseConsumer
1317+
String id, Integer width, Boolean download, Boolean ignoremalware, ResponseConsumer responseConsumer
13161318
) throws MoeraNodeException {
13171319
var location = "/media/private/%s/data".formatted(ue(id));
13181320
var params = new QueryParam[] {
13191321
QueryParam.of("width", width),
1320-
QueryParam.of("download", download)
1322+
QueryParam.of("download", download),
1323+
QueryParam.of("ignoremalware", ignoremalware)
13211324
};
13221325
call(location, params, "GET", null, responseConsumer);
13231326
}
@@ -1334,6 +1337,21 @@ public PrivateMediaFileInfo getPrivateMediaInfo(String id) throws MoeraNodeExcep
13341337
return call(location, null, "GET", null, returnTypeRef);
13351338
}
13361339

1340+
/**
1341+
* Update media file details.
1342+
*
1343+
* @param id media file ID
1344+
* @param attributes attributes
1345+
* @return PrivateMediaFileInfo
1346+
*/
1347+
public PrivateMediaFileInfo updatePrivateMediaInfo(
1348+
String id, PrivateMediaFileAttributes attributes
1349+
) throws MoeraNodeException {
1350+
var location = "/media/private/%s/info".formatted(ue(id));
1351+
var returnTypeRef = new TypeReference<PrivateMediaFileInfo>() {};
1352+
return call(location, null, "PUT", attributes, returnTypeRef);
1353+
}
1354+
13371355
/**
13381356
* Get the list of all postings and comments the media file is attached to.
13391357
*
@@ -2218,6 +2236,19 @@ public AsyncOperationCreated verifyRemoteCommentReaction(
22182236
return call(location, null, "POST", Collections.emptyMap(), returnTypeRef);
22192237
}
22202238

2239+
/**
2240+
* Download the private media file from the remote node and store it at the home node.
2241+
*
2242+
* @param nodeName name of the remote node
2243+
* @param id id of the media file
2244+
* @return PrivateMediaFileInfo
2245+
*/
2246+
public PrivateMediaFileInfo downloadRemoteMedia(String nodeName, String id) throws MoeraNodeException {
2247+
var location = "/nodes/%s/media/private/%s/download".formatted(ue(nodeName), ue(id));
2248+
var returnTypeRef = new TypeReference<PrivateMediaFileInfo>() {};
2249+
return call(location, null, "POST", Collections.emptyMap(), returnTypeRef);
2250+
}
2251+
22212252
/**
22222253
* Add a posting to the remote node and register it in the registry at the local node.
22232254
*
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package org.moera.lib.node.types;
2+
3+
// This file is generated
4+
5+
import com.fasterxml.jackson.annotation.JsonInclude;
6+
import org.moera.lib.node.types.validate.ValidationUtil;
7+
8+
@JsonInclude(JsonInclude.Include.NON_NULL)
9+
public class PrivateMediaFileAttributes extends Structure implements Cloneable {
10+
11+
private String title;
12+
13+
/**
14+
* Retrieves title of the media file, may be used as an alternative to the file name.
15+
*
16+
* @return the value
17+
*/
18+
public String getTitle() {
19+
return title;
20+
}
21+
22+
/**
23+
* Sets title of the media file, may be used as an alternative to the file name.
24+
*
25+
* @param title the value to be set
26+
*/
27+
public void setTitle(String title) {
28+
this.title = title;
29+
}
30+
31+
@Override
32+
public void validate() {
33+
super.validate();
34+
ValidationUtil.maxSize(title, 255, "media.title.wrong-size");
35+
}
36+
37+
/**
38+
* Creates and returns a copy of this {@code PrivateMediaFileAttributes} object.
39+
*
40+
* @return a clone of this instance
41+
*/
42+
@Override
43+
public PrivateMediaFileAttributes clone() {
44+
try {
45+
return (PrivateMediaFileAttributes) super.clone();
46+
} catch (CloneNotSupportedException e) {
47+
throw new IllegalArgumentException("Must implement Cloneable", e);
48+
}
49+
}
50+
51+
}

src/main/java/org/moera/lib/node/types/PrivateMediaFileInfo.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ public class PrivateMediaFileInfo extends Structure implements Cloneable {
1919
private Integer height;
2020
private Short orientation;
2121
private long size;
22+
private String title;
2223
private String textContent;
2324
private String postingId;
2425
private List<MediaFilePreviewInfo> previews;
26+
private Boolean attachment;
27+
private Boolean malware;
2528
private PrivateMediaFileOperations operations;
2629

2730
/**
@@ -218,6 +221,24 @@ public void setSize(long size) {
218221
this.size = size;
219222
}
220223

224+
/**
225+
* Retrieves title of the media file, may be used as an alternative to the file name.
226+
*
227+
* @return the value
228+
*/
229+
public String getTitle() {
230+
return title;
231+
}
232+
233+
/**
234+
* Sets title of the media file, may be used as an alternative to the file name.
235+
*
236+
* @param title the value to be set
237+
*/
238+
public void setTitle(String title) {
239+
this.title = title;
240+
}
241+
221242
/**
222243
* Retrieves the text contained in the image, if any.
223244
*
@@ -272,6 +293,49 @@ public void setPreviews(List<MediaFilePreviewInfo> previews) {
272293
this.previews = previews;
273294
}
274295

296+
/**
297+
* Retrieves <code>true</code> if the media cannot be displayed as an image or video and should be displayed as an
298+
* attachment instead, <code>false</code> (default) otherwise
299+
* .
300+
*
301+
* @return the value
302+
*/
303+
public Boolean getAttachment() {
304+
return attachment;
305+
}
306+
307+
/**
308+
* Sets <code>true</code> if the media cannot be displayed as an image or video and should be displayed as an
309+
* attachment instead, <code>false</code> (default) otherwise
310+
* .
311+
*
312+
* @param attachment the value to be set
313+
*/
314+
public void setAttachment(Boolean attachment) {
315+
this.attachment = attachment;
316+
}
317+
318+
/**
319+
* Retrieves <code>true</code> if the media file is considered to be malware, <code>false</code> (default)
320+
* otherwise
321+
* .
322+
*
323+
* @return the value
324+
*/
325+
public Boolean getMalware() {
326+
return malware;
327+
}
328+
329+
/**
330+
* Sets <code>true</code> if the media file is considered to be malware, <code>false</code> (default) otherwise
331+
* .
332+
*
333+
* @param malware the value to be set
334+
*/
335+
public void setMalware(Boolean malware) {
336+
this.malware = malware;
337+
}
338+
275339
/**
276340
* Retrieves the supported operations and the corresponding principals.
277341
*

src/main/java/org/moera/lib/node/types/PrivateMediaFileOperations.java

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
public class PrivateMediaFileOperations implements Cloneable {
1313

1414
private Principal view;
15+
private Principal edit;
1516

1617
/**
1718
* Retrieves the permission to view the media file.
@@ -67,14 +68,69 @@ public void setView(Principal view, Principal defaultValue) {
6768
this.view = Objects.equals(view, defaultValue) ? null : view;
6869
}
6970

71+
/**
72+
* Retrieves the permission to edit the media file attributes.
73+
* If {@code null}, the default permission is in effect.
74+
*
75+
* @return the permission, may be {@code null}
76+
*/
77+
public Principal getEdit() {
78+
return edit;
79+
}
80+
81+
/**
82+
* Retrieves the permission to edit the media file attributes,
83+
* or {@code defaultValue} if the permission is {@code null}.
84+
*
85+
* @param defaultValue the default permission
86+
* @return the permission
87+
*/
88+
public Principal getEdit(Principal defaultValue) {
89+
return edit != null ? edit : defaultValue;
90+
}
91+
92+
/**
93+
* Retrieves the permission to edit the media file attributes,
94+
* or {@code defaultValue} if {@code operations} is {@code null} or the permission is {@code null}.
95+
*
96+
* @param operations permissions data
97+
* @param defaultValue the default permission
98+
* @return the permission
99+
*/
100+
public static Principal getEdit(PrivateMediaFileOperations operations, Principal defaultValue) {
101+
return operations != null ? operations.getEdit(defaultValue) : defaultValue;
102+
}
103+
104+
/**
105+
* Sets the permission to edit the media file attributes.
106+
* If set to {@code null}, the default permission should be used.
107+
*
108+
* @param edit the permission to set, may be {@code null}
109+
*/
110+
public void setEdit(Principal edit) {
111+
this.edit = edit;
112+
}
113+
114+
/**
115+
* Sets the permission to edit the media file attributes.
116+
* If the value is equal to {@code defaultValue}, the permission is set to {@code null}.
117+
*
118+
* @param edit the permission to set
119+
* @param defaultValue the default permission
120+
*/
121+
public void setEdit(Principal edit, Principal defaultValue) {
122+
this.edit = Objects.equals(edit, defaultValue) ? null : edit;
123+
}
124+
70125
/**
71126
* Checks if all the permissions in the object are {@code null}.
72127
*
73128
* @return {@code true} if all the permissions are {@code null}, {@code false} otherwise.
74129
*/
75130
@JsonIgnore
76131
public boolean isEmpty() {
77-
return view == null;
132+
return view == null
133+
&& edit == null;
78134
}
79135

80136
/**

src/main/java/org/moera/lib/node/types/RemoteMedia.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public class RemoteMedia extends Structure implements Cloneable {
1010
private String id;
1111
private String hash;
1212
private String digest;
13+
private String mimeType;
14+
private Boolean attachment;
1315

1416
/**
1517
* Retrieves ID of the media file.
@@ -65,6 +67,46 @@ public void setDigest(String digest) {
6567
this.digest = digest;
6668
}
6769

70+
/**
71+
* Retrieves MIME type of the media.
72+
*
73+
* @return the value
74+
*/
75+
public String getMimeType() {
76+
return mimeType;
77+
}
78+
79+
/**
80+
* Sets MIME type of the media.
81+
*
82+
* @param mimeType the value to be set
83+
*/
84+
public void setMimeType(String mimeType) {
85+
this.mimeType = mimeType;
86+
}
87+
88+
/**
89+
* Retrieves <code>true</code> if the media cannot be displayed as an image or video and should be displayed as an
90+
* attachment instead, <code>false</code> (default) otherwise
91+
* .
92+
*
93+
* @return the value
94+
*/
95+
public Boolean getAttachment() {
96+
return attachment;
97+
}
98+
99+
/**
100+
* Sets <code>true</code> if the media cannot be displayed as an image or video and should be displayed as an
101+
* attachment instead, <code>false</code> (default) otherwise
102+
* .
103+
*
104+
* @param attachment the value to be set
105+
*/
106+
public void setAttachment(Boolean attachment) {
107+
this.attachment = attachment;
108+
}
109+
68110
/**
69111
* Creates and returns a copy of this {@code RemoteMedia} object.
70112
*

0 commit comments

Comments
 (0)