MCPcopy Create free account
hub / github.com/TrsstProject/trsst / postMedia

Method postMedia

src/main/java/com/trsst/server/TrsstAdapter.java:643–743  ·  view source on GitHub ↗

Accepts a signed feed document containing one or more signed entries and attachments for some or all of those entries.

(RequestContext request)

Source from the content-addressed store, hash-verified

641 * attachments for some or all of those entries.
642 */
643 public ResponseContext postMedia(RequestContext request) {
644 try {
645 if (MimeTypeHelper.isMultipart(request.getContentType().toString())) {
646 byte[] requestData = Common.readFully(request.getInputStream());
647 List<MultipartRelatedPost> posts = getMultipartRelatedData(
648 request, new ByteArrayInputStream(requestData));
649 Feed incomingFeed = null;
650 if (posts != null) {
651 Map<String, Entry> contentIdToEntry = new HashMap<String, Entry>();
652 Map<String, String> contentIdToType = new HashMap<String, String>();
653 Map<String, InputStream> contentIdToData = new HashMap<String, InputStream>();
654 for (MultipartRelatedPost post : posts) {
655 String type = post.getDataHeaders().get("content-type");
656 String cid = post.getDataHeaders().get("content-id");
657 if (cid != null) {
658 if (cid.startsWith("<cid:")) {
659 cid = cid.substring(5);
660 cid = cid.substring(0, cid.length() - 1);
661 }
662 // find content id in entry list
663 List<Entry> entries;
664 if (post.getSource().getRoot() instanceof Feed) {
665 incomingFeed = ((Feed) post.getSource()
666 .getRoot());
667 entries = incomingFeed.getEntries();
668 } else if (post.getSource().getRoot() instanceof Entry) {
669 log.warn("Single entries not supported: "
670 + post.getSource().getRoot());
671 entries = new LinkedList<Entry>();
672 entries.add((Entry) post.getSource().getRoot());
673 return ProviderHelper
674 .badrequest(request,
675 "Single entries not currently supported.");
676 } else {
677 log.error("Unrecognized source: "
678 + post.getSource());
679 return ProviderHelper.badrequest(request,
680 "Unrecognized source.");
681 }
682 for (Entry entry : entries) {
683 if (entry.getContentSrc() != null
684 && entry.getContentSrc().toString()
685 .endsWith(cid)) {
686 // getContentSrc resolves against baseurl
687 contentIdToEntry.put(cid, entry);
688 contentIdToType.put(cid, type);
689 contentIdToData.put(cid, post.getData());
690 }
691 }
692 }
693 }
694 // if all content ids match an entry content element
695 if (contentIdToEntry.size() == posts.size()) {
696 ingestFeed(persistence, incomingFeed);
697 for (Map.Entry<String, Entry> i : contentIdToEntry
698 .entrySet()) {
699 String cid = i.getKey();
700 Entry entry = i.getValue();

Callers

nothing calls this directly

Calls 15

readFullyMethod · 0.95
ingestFeedMethod · 0.95
ripemd160Method · 0.95
toEntryIdMethod · 0.95
pushRawPostIfNeededMethod · 0.95
getContentTypeMethod · 0.80
getMethod · 0.80
getDataHeadersMethod · 0.80
getSourceMethod · 0.80
putMethod · 0.80
getDataMethod · 0.80

Tested by

no test coverage detected