Skip to content

Commit f873247

Browse files
committed
chore: unify authentication, storage objects, annotation creation
1 parent 9d79b1b commit f873247

File tree

76 files changed

+63046
-27633
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+63046
-27633
lines changed

package-lock.json

+35,491-14,497
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "A textual annotation management system.",
55
"main": "index.js",
66
"scripts": {
7-
"lerna": "lerna"
7+
"lerna": "lerna",
8+
"lerna:bootstrap": "lerna bootstrap --hoist -- --legacy-peer-deps"
89
},
910
"repository": {
1011
"type": "git",

packages/android/app/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ dependencies {
8888
implementation 'com.google.android.gms:play-services-auth:19.0.0'
8989

9090
implementation 'io.sentry:sentry-android:4.3.0'
91+
implementation 'net.jodah:failsafe:2.4.0'
9192

9293
// Amplitude
9394
implementation 'com.amplitude:android-sdk:2.25.2'

packages/android/app/src/main/graphql/schema.json

+57-38
Original file line numberDiff line numberDiff line change
@@ -1942,6 +1942,21 @@
19421942
"description" : null,
19431943
"isDeprecated" : false,
19441944
"deprecationReason" : null
1945+
}, {
1946+
"name" : "APPLICATION_X_MIMEARCHIVE",
1947+
"description" : null,
1948+
"isDeprecated" : false,
1949+
"deprecationReason" : null
1950+
}, {
1951+
"name" : "APPLICATION_OCTET_STREAM",
1952+
"description" : null,
1953+
"isDeprecated" : false,
1954+
"deprecationReason" : null
1955+
}, {
1956+
"name" : "IMAGE_PNG",
1957+
"description" : null,
1958+
"isDeprecated" : false,
1959+
"deprecationReason" : null
19451960
} ],
19461961
"possibleTypes" : null
19471962
}, {
@@ -7934,15 +7949,19 @@
79347949
"name" : "selector",
79357950
"description" : null,
79367951
"type" : {
7937-
"kind" : "LIST",
7952+
"kind" : "NON_NULL",
79387953
"name" : null,
79397954
"ofType" : {
7940-
"kind" : "NON_NULL",
7955+
"kind" : "LIST",
79417956
"name" : null,
79427957
"ofType" : {
7943-
"kind" : "INPUT_OBJECT",
7944-
"name" : "SelectorInput",
7945-
"ofType" : null
7958+
"kind" : "NON_NULL",
7959+
"name" : null,
7960+
"ofType" : {
7961+
"kind" : "INPUT_OBJECT",
7962+
"name" : "SelectorInput",
7963+
"ofType" : null
7964+
}
79467965
}
79477966
}
79487967
},
@@ -9713,12 +9732,12 @@
97139732
"onFragment" : false,
97149733
"onField" : true
97159734
}, {
9716-
"name" : "aws_publish",
9717-
"description" : "Tells the service which subscriptions will be published to when this mutation is called. This directive is deprecated use @aws_susbscribe directive instead.",
9735+
"name" : "aws_subscribe",
9736+
"description" : "Tells the service which mutation triggers this subscription.",
97189737
"locations" : [ "FIELD_DEFINITION" ],
97199738
"args" : [ {
9720-
"name" : "subscriptions",
9721-
"description" : "List of subscriptions which will be published to when this mutation is called.",
9739+
"name" : "mutations",
9740+
"description" : "List of mutations which will trigger this subscription when they are called.",
97229741
"type" : {
97239742
"kind" : "LIST",
97249743
"name" : null,
@@ -9734,12 +9753,12 @@
97349753
"onFragment" : false,
97359754
"onField" : false
97369755
}, {
9737-
"name" : "aws_subscribe",
9738-
"description" : "Tells the service which mutation triggers this subscription.",
9756+
"name" : "aws_auth",
9757+
"description" : "Directs the schema to enforce authorization on a field",
97399758
"locations" : [ "FIELD_DEFINITION" ],
97409759
"args" : [ {
9741-
"name" : "mutations",
9742-
"description" : "List of mutations which will trigger this subscription when they are called.",
9760+
"name" : "cognito_groups",
9761+
"description" : "List of cognito user pool groups which have access on this field",
97439762
"type" : {
97449763
"kind" : "LIST",
97459764
"name" : null,
@@ -9755,12 +9774,12 @@
97559774
"onFragment" : false,
97569775
"onField" : false
97579776
}, {
9758-
"name" : "aws_auth",
9759-
"description" : "Directs the schema to enforce authorization on a field",
9777+
"name" : "aws_publish",
9778+
"description" : "Tells the service which subscriptions will be published to when this mutation is called. This directive is deprecated use @aws_susbscribe directive instead.",
97609779
"locations" : [ "FIELD_DEFINITION" ],
97619780
"args" : [ {
9762-
"name" : "cognito_groups",
9763-
"description" : "List of cognito user pool groups which have access on this field",
9781+
"name" : "subscriptions",
9782+
"description" : "List of subscriptions which will be published to when this mutation is called.",
97649783
"type" : {
97659784
"kind" : "LIST",
97669785
"name" : null,
@@ -9776,8 +9795,8 @@
97769795
"onFragment" : false,
97779796
"onField" : false
97789797
}, {
9779-
"name" : "aws_iam",
9780-
"description" : "Tells the service this field/object has access authorized by sigv4 signing.",
9798+
"name" : "aws_oidc",
9799+
"description" : "Tells the service this field/object has access authorized by an OIDC token.",
97819800
"locations" : [ "OBJECT", "FIELD_DEFINITION" ],
97829801
"args" : [ ],
97839802
"onOperation" : false,
@@ -9792,27 +9811,18 @@
97929811
"onFragment" : false,
97939812
"onField" : false
97949813
}, {
9795-
"name" : "aws_api_key",
9796-
"description" : "Tells the service this field/object has access authorized by an API key.",
9814+
"name" : "aws_iam",
9815+
"description" : "Tells the service this field/object has access authorized by sigv4 signing.",
97979816
"locations" : [ "OBJECT", "FIELD_DEFINITION" ],
97989817
"args" : [ ],
97999818
"onOperation" : false,
98009819
"onFragment" : false,
98019820
"onField" : false
98029821
}, {
9803-
"name" : "deprecated",
9804-
"description" : null,
9805-
"locations" : [ "FIELD_DEFINITION", "ENUM_VALUE" ],
9806-
"args" : [ {
9807-
"name" : "reason",
9808-
"description" : null,
9809-
"type" : {
9810-
"kind" : "SCALAR",
9811-
"name" : "String",
9812-
"ofType" : null
9813-
},
9814-
"defaultValue" : "\"No longer supported\""
9815-
} ],
9822+
"name" : "aws_api_key",
9823+
"description" : "Tells the service this field/object has access authorized by an API key.",
9824+
"locations" : [ "OBJECT", "FIELD_DEFINITION" ],
9825+
"args" : [ ],
98169826
"onOperation" : false,
98179827
"onFragment" : false,
98189828
"onField" : false
@@ -9838,10 +9848,19 @@
98389848
"onFragment" : false,
98399849
"onField" : false
98409850
}, {
9841-
"name" : "aws_oidc",
9842-
"description" : "Tells the service this field/object has access authorized by an OIDC token.",
9843-
"locations" : [ "OBJECT", "FIELD_DEFINITION" ],
9844-
"args" : [ ],
9851+
"name" : "deprecated",
9852+
"description" : null,
9853+
"locations" : [ "FIELD_DEFINITION", "ENUM_VALUE" ],
9854+
"args" : [ {
9855+
"name" : "reason",
9856+
"description" : null,
9857+
"type" : {
9858+
"kind" : "SCALAR",
9859+
"name" : "String",
9860+
"ofType" : null
9861+
},
9862+
"defaultValue" : "\"No longer supported\""
9863+
} ],
98459864
"onOperation" : false,
98469865
"onFragment" : false,
98479866
"onField" : false

packages/android/app/src/main/java/io/literal/lib/ContentResolverLib.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
import java.io.InputStream;
1212

1313
public class ContentResolverLib {
14-
public static File toFile (Context context, Uri uri, String fileName) {
14+
public static File toFile (Context context, File directory, Uri uri, String fileName) {
1515
try {
1616
InputStream inputStream = context.getContentResolver().openInputStream(uri);
17-
File outputFile = new File(context.getFilesDir(), fileName);
17+
File outputFile = new File(directory, fileName);
1818
FileUtils.copyInputStreamToFile(inputStream, outputFile);
1919
return outputFile;
2020
} catch (IOException e) {

packages/android/app/src/main/java/io/literal/model/Annotation.java

+51
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,20 @@
55
import org.json.JSONException;
66
import org.json.JSONObject;
77

8+
import java.security.NoSuchAlgorithmException;
89
import java.util.Arrays;
910
import java.util.Collections;
11+
import java.util.UUID;
1012
import java.util.stream.Collectors;
1113
import java.util.stream.Stream;
1214

1315
import io.literal.lib.AnnotationLib;
16+
import io.literal.lib.AnnotationTargetLib;
17+
import io.literal.lib.Constants;
18+
import io.literal.lib.Crypto;
1419
import io.literal.lib.JsonArrayUtil;
20+
import io.literal.lib.WebRoutes;
21+
import io.literal.repository.ErrorRepository;
1522
import type.AnnotationType;
1623
import type.CreateAnnotationInput;
1724

@@ -93,4 +100,48 @@ public CreateAnnotationInput toCreateAnnotationInput() {
93100
: null
94101
).build();
95102
}
103+
104+
public static Annotation fromText(String text, String creatorUsername) {
105+
try {
106+
String valueHash = Crypto.sha256Hex(text);
107+
String annotationId = WebRoutes.creatorsIdAnnotationId(
108+
WebRoutes.getAPIHost(),
109+
creatorUsername,
110+
valueHash
111+
);
112+
113+
Body[] bodies = { TextualBody.createTag(Constants.RECENT_ANNOTATION_COLLECTION_LABEL, creatorUsername) };
114+
Target[] targets = { new TextualTarget(AnnotationTargetLib.makeId(annotationId), text) };
115+
return new Annotation(
116+
bodies,
117+
targets,
118+
new Motivation[] { Motivation.HIGHLIGHTING },
119+
null,
120+
null,
121+
annotationId
122+
);
123+
} catch (NoSuchAlgorithmException ex) {
124+
ErrorRepository.captureException(ex);
125+
return null;
126+
}
127+
}
128+
129+
public static Annotation fromScreenshot(StorageObject screenshot, String creatorUsername) {
130+
String annotationId = WebRoutes.creatorsIdAnnotationId(
131+
WebRoutes.getAPIHost(),
132+
creatorUsername,
133+
UUID.randomUUID().toString()
134+
);
135+
Body[] bodies = { TextualBody.createTag(Constants.RECENT_ANNOTATION_COLLECTION_LABEL, creatorUsername) };
136+
Target[] targets = { ExternalTarget.create(screenshot) };
137+
138+
return new Annotation(
139+
bodies,
140+
targets,
141+
new Motivation[] { Motivation.HIGHLIGHTING },
142+
null,
143+
null,
144+
annotationId
145+
);
146+
}
96147
}

0 commit comments

Comments
 (0)