Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[WIP] generate a sharable image/png when copying#170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
li-xin-yi wants to merge1 commit intocodepod-io:main
base:main
Choose a base branch
Loading
fromli-xin-yi:experimental/pic

Conversation

li-xin-yi
Copy link
Collaborator

@li-xin-yili-xin-yi commentedDec 24, 2022
edited
Loading

I use this API ofcarbon:https://github.com/petersolopov/carbonara

Notice thatlocalhost doesn't allowCROS, we can't send a request ofapplication/json payload tolocalhost:3099/api/cook, the actual request body is intext/plain format. So you may need to skip the content type checking by deleting this linehttps://github.com/petersolopov/carbonara/blob/master/src/utils.js#L118, and then run the deployment command of this api by:

git clone https://github.com/petersolopov/carbonaracd carbonaradocker build -t local/carbonara .docker run -p 3099:3000 local/carbonara -it

To test if the api running normally, run acURL command:

curl -L http://127.0.0.1:3099/api/cook \-X POST \-H'Content-Type: application/json' \-d'{        "code": "sum(range(114))"    }' \> test.png

image

Now, the fetch request can be viewed with correct preview in devtools, I just wonder how to take it out.

image

@li-xin-yili-xin-yi marked this pull request as draftDecember 24, 2022 22:53
@li-xin-yi
Copy link
CollaboratorAuthor

The API even works well with Python requests:

image

I noticed that in no-CORS mode, the request type is opaque, so I can't get the response body (seethis answer). I forced no-CORS mode because the hostnamelocalhost in the request URL seems to disable CORS (seethis question and answers due to the ngnix setting for our CodePod running onlocalhost. A proxy or any other may need to add to our ngnix server to enable CORS.

@lihebi Do you have any idea or suggestion with it?

};
const res = await fetch("http://localhost:3099/api/cook", requesOptions);
const pic = await res.blob();
// navigator.clipboard.write([new ClipboardItem({ "image/png": pic })]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think thisnavigator.clipboard.write works. I can paste the image to Google Slides:

Screenshot 2022-12-26 at 6 19 08 PM

method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ code: pod.content }),
mode: "no-cors" as RequestMode,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

CORS seems problematic. Let's add an Nginx route.

# nginx.conflocation /carbon {        rewrite ^/carbon(.*)$$1break;        proxy_pass http://carbon:3000;}

and in compose.yml, add a container:

carbon:    image: local/carbonara

The request URL will behttp://localhost/carbon/api/cook

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@lihebilihebilihebi left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@li-xin-yi@lihebi

[8]ページ先頭

©2009-2025 Movatter.jp