resolve method
What to serve for documentId.
The published version, unless preview is a valid, unexpired link for a
version of this document. A link that fails verification serves the
published version and reports DV-CONTENT-001 -- not the draft, and not
a 404, because the published page is the honest answer to the route.
Implementation
Future<DVContentServed<T>?> resolve(
String documentId, {
String? preview,
}) async {
if (preview != null) {
final String? versionId = _verifyPreview(preview, documentId);
final DVContentVersion<T>? named = versionId == null
? null
: await version(versionId);
if (named != null && named.documentId == documentId) {
return DVContentServed<T>._(
named,
isPreview: named.state != DVContentState.published,
cacheTags: named.state == DVContentState.published
? _tagsFor(named)
: const <String>[],
);
}
_report(
DVContentReport._(
DVContentReportKind.previewRejected,
'a preview link for $kind:$documentId failed verification or had '
'expired; the published version was served',
versionId: versionId,
),
);
}
final DVContentVersion<T>? live = await current(documentId);
if (live == null) return null;
return DVContentServed<T>._(
live,
isPreview: false,
cacheTags: _tagsFor(live),
);
}