Skip to content

Commit

Permalink
Add encrypted content flag to analysis
Browse files Browse the repository at this point in the history
See #33
  • Loading branch information
amake committed Dec 24, 2023
1 parent 72b09bc commit 6cc3f20
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions lib/src/components/document_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,38 +182,52 @@ Future<DocumentAnalysis> _analyze(OrgTree doc) => time('analyze', () async {
await canObtainNativeDirectoryPermissions();
var hasRemoteImages = false;
var hasRelativeLinks = false;
doc.visit<OrgLink>((link) {
hasRemoteImages |=
looksLikeImagePath(link.location) && looksLikeUrl(link.location);
try {
hasRelativeLinks |= OrgFileLink.parse(link.location).isRelative;
} on Exception {
// Not a file link
var hasEncryptedContent = false;
doc.visit<OrgLeafNode>((node) {
if (node is OrgLink) {
hasRemoteImages |=
looksLikeImagePath(node.location) && looksLikeUrl(node.location);
try {
hasRelativeLinks |= OrgFileLink.parse(node.location).isRelative;
} on Exception {
// Not a file link
}
return !hasRemoteImages ||
(!hasRelativeLinks && canResolveRelativeLinks) ||
!hasEncryptedContent;
} else if (node is OrgPgpBlock) {
hasEncryptedContent = true;
return !hasRemoteImages ||
(!hasRelativeLinks && canResolveRelativeLinks);
}
return !hasRemoteImages ||
(!hasRelativeLinks && canResolveRelativeLinks);
return true;
});
return DocumentAnalysis(
hasRemoteImages: hasRemoteImages,
hasRelativeLinks: hasRelativeLinks,
hasEncryptedContent: hasEncryptedContent,
);
});

class DocumentAnalysis {
const DocumentAnalysis({
this.hasRemoteImages,
this.hasRelativeLinks,
this.hasEncryptedContent,
});

final bool? hasRemoteImages;
final bool? hasRelativeLinks;
final bool? hasEncryptedContent;

@override
bool operator ==(Object other) =>
other is DocumentAnalysis &&
hasRemoteImages == other.hasRemoteImages &&
hasRelativeLinks == other.hasRelativeLinks;
hasRelativeLinks == other.hasRelativeLinks &&
hasEncryptedContent == other.hasEncryptedContent;

@override
int get hashCode => Object.hash(hasRemoteImages, hasRelativeLinks);
int get hashCode =>
Object.hash(hasRemoteImages, hasRelativeLinks, hasEncryptedContent);
}

0 comments on commit 6cc3f20

Please sign in to comment.