keyoxide/keyoxide-web
26
329
Fork
You've already forked keyoxide-web
39

Implement schema.org proxy route #195

Open
opened 2024年03月04日 09:49:20 +01:00 by vladimyr · 0 comments

Proposal

Based on the need to scrape embedded schema.org structured data from LinkedIn post pages (as described here) and potential future use cases involving schema.org I propose implementing new /api/3/get/ proxy route. This new /api/3/get/schemaorg proxy route would work much like /api/3/get/activitypub:

  • it would accept url query param with the target URL containing embedded schema.org structured data
  • it would accept type query param containing valid schema.org type
  • it would return the first occurrence of scrapped schema.org JSON data matching required type with Content-Type set to application/ld+json

The scraper needs to:

  1. find all script[type="application/ld+json"] elements and extract their JSON payload
  2. filter out those who's $["@context"] !== "http://schema.org"
  3. return the first payload whose type matches the requested type: $["@type"] === query.type

Using @martin.sweeney 's example post from keyoxide/doipjs#18, the request would look like this:

GET https://keyoxide.org/api/3/get/schemaorg?type=SocialMediaPosting&url=https://www.linkedin.com/posts/martinsweeny_verifying-my-openpgp-key-openpgp4fpr08a83f21244c4876d9ec2c6a5f88f7e8f01d4198-activity-6884620821181063168-WsxX

and it would return:

Content-Type: application/ld+json
{
 "@context": "http://schema.org",
 "@type": "SocialMediaPosting",
 "@id": "https://www.linkedin.com/posts/martinsweeny_verifying-my-openpgp-key-openpgp4fpr08a83f21244c4876d9ec2c6a5f88f7e8f01d4198-activity-6884620821181063168-WsxX",
 "author": {
 "name": "Martin â–1⁄2 Sweeny",
 "image": {
 "url": "https://media.licdn.com/dms/image/D4E03AQEPi12R3WJiLg/profile-displayphoto-shrink_200_200/0/1693155735016?e=2147483647&v=beta&t=F9Zmr1SdpAZJ-tvqRRCzIk7Gnugofrj48Y6c-NUGw2w",
 "@type": "ImageObject"
 },
 "url": "https://ca.linkedin.com/in/martinsweeny",
 "@type": "Person"
 },
 "datePublished": "2022年01月05日T22:25:13.826Z",
 "articleBody": "[Verifying my OpenPGP key: openpgp4fpr:08a83f21244c4876d9ec2c6a5f88f7e8f01d4198]",
 "hasPart": {
 "@type": "WebPageElement",
 "isAccessibleForFree": false,
 "cssSelector": ".details"
 }
}
### Proposal Based on the need to scrape embedded schema.org structured data from LinkedIn post pages (as described [here](https://codeberg.org/keyoxide/doipjs/pulls/18#issuecomment-1637237)) and potential future use cases involving schema.org I propose implementing new [`/api/3/get/` proxy route](https://codeberg.org/keyoxide/keyoxide-web/src/commit/b8c94ebc0b/src/api/v3/proxy_get.js). This new `/api/3/get/schemaorg` proxy route would work much like [`/api/3/get/activitypub`](https://spec.keyoxide.org/spec/2/#:~:text=Returns%3A%20JSON%20object-,%2Fapi%2F3%2Fget%2Factivitypub,Returns%3A%20JSON%20object,-4.%20Data%20schemas): - it would accept `url` query param with the target URL containing embedded schema.org structured data - it would accept `type` query param containing valid [schema.org type](https://schema.org/docs/full.html) - it would return the first occurrence of scrapped schema.org JSON data matching required `type` with `Content-Type` set to `application/ld+json` The scraper needs to: 1. find all `script[type="application/ld+json"]` elements and extract their JSON payload 2. filter out those who's `$["@context"] !== "http://schema.org"` 3. return the first payload whose type matches the requested type: `$["@type"] === query.type` Using @martin.sweeney 's example post from https://codeberg.org/keyoxide/doipjs/pulls/18, the request would look like this: ``` GET https://keyoxide.org/api/3/get/schemaorg?type=SocialMediaPosting&url=https://www.linkedin.com/posts/martinsweeny_verifying-my-openpgp-key-openpgp4fpr08a83f21244c4876d9ec2c6a5f88f7e8f01d4198-activity-6884620821181063168-WsxX ``` and it would return: ``` Content-Type: application/ld+json { "@context": "http://schema.org", "@type": "SocialMediaPosting", "@id": "https://www.linkedin.com/posts/martinsweeny_verifying-my-openpgp-key-openpgp4fpr08a83f21244c4876d9ec2c6a5f88f7e8f01d4198-activity-6884620821181063168-WsxX", "author": { "name": "Martin â–1⁄2 Sweeny", "image": { "url": "https://media.licdn.com/dms/image/D4E03AQEPi12R3WJiLg/profile-displayphoto-shrink_200_200/0/1693155735016?e=2147483647&v=beta&t=F9Zmr1SdpAZJ-tvqRRCzIk7Gnugofrj48Y6c-NUGw2w", "@type": "ImageObject" }, "url": "https://ca.linkedin.com/in/martinsweeny", "@type": "Person" }, "datePublished": "2022年01月05日T22:25:13.826Z", "articleBody": "[Verifying my OpenPGP key: openpgp4fpr:08a83f21244c4876d9ec2c6a5f88f7e8f01d4198]", "hasPart": { "@type": "WebPageElement", "isAccessibleForFree": false, "cssSelector": ".details" } } ```
Sign in to join this conversation.
dev
main
dev
redesign-2023
add-logging
5.1.0
5.0.1
5.0.0
5.0.0-rc.1
4.2.7
4.2.6
4.2.5
4.2.4
4.2.3
4.2.2
4.2.1
4.2.0
4.1.1
4.1.0
4.0.2
4.0.1
4.0.0
3.6.4
3.6.3
3.6.2
3.6.1
3.6.0
3.5.2
3.5.1
3.5.0
3.4.18
3.4.17
3.4.16
3.4.15
3.4.14
3.4.13
3.4.12
3.4.11
3.4.10
3.4.9
3.4.8
3.4.7
3.4.6
3.4.5
3.4.4
3.4.3
3.4.2
3.4.1
3.4.0
3.3.1
3.3.0
3.2.0
3.1.1
3.1.0
3.0.4
3.0.3
3.0.2
3.0.1
3.0.0
2.5.0
2.4.2
2.4.1
2.4.0
2.3.4
2.3.3
2.3.2
2.3.1
2.3.0
2.2.8
2.2.7
2.2.6
2.2.5
2.2.4
2.2.3
2.2.2
2.2.1
2.2.0
2.1.1
2.1.0
2.0.2
2.0.1
2.0.0
2.0.0-rc.3
2.0.0-rc.2
2.0.0-rc.1
1.0.0
0.4.0
0.3.1
0.3.0
0.2.1
0.2.0
0.1.0
Labels
Clear labels
bug
Something is not working

Archived

contribution welcome
Contributions are very welcome, get started here

Archived

enhancement
New feature

Archived

good first issue
Interested in contributing? Get started here.

Archived

Contribution welcome
Get started contributing here
Good first issue
Good if you are new to the project or to open source contributions
Impact
External
Affects the people using the project
Impact
Internal
Affects on the people working on the project
Priority
Critical
Work on right now
Priority
High
Work on at earliest convenience
Priority
Low
Work on in spare time
Priority
Medium
Work on regularly
Review
Duplicate
Already exists
Review
Off Topic
Does not fall within the scope of the repo/project
Status
Backlog
Is not being worked on yet
Status
Blocked
Is waiting on something or someone
Status
Completed
Is done
Status
In Progress
Is being worked on
Status
Investigating
Is waiting on research or questions
Status
Needs Decision
Is waiting on a decision by the devs/contributors
Status
Needs Info
Is waiting on additional information before it can be solved
Status
Needs Triage
Is new issue that needs reviewing
Status
Testing
Is being checked and verified
Status
Waiting For Review
Is waiting on reviewers to approve
Status
Won't Fix
Won't be fixed
Type
Bug
Related to something not working as intended
Type
CI
Related to continuous integration
Type
Documentation
Related to documentation
Type
Enhancement
Related to a new feature or an improved one
Type
New Claim
Related to a new identity claim/proof
Type
Security
Related to security
Type
Tests
Related to code tests
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
keyoxide/keyoxide-web#195
Reference in a new issue
keyoxide/keyoxide-web
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?