Skip to content

Instantly share code, notes, and snippets.

@rowntreerob
Created May 13, 2023 01:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rowntreerob/3bf4db2a64afc8ec3a6bd7e1caef9b90 to your computer and use it in GitHub Desktop.
Save rowntreerob/3bf4db2a64afc8ec3a6bd7e1caef9b90 to your computer and use it in GitHub Desktop.
/* once a bookmarklet has done the dom manipulation and created html to preserve the chatgpt,
the html can be posted to a separate service that implements the gist api for create
*/
app.use(express.raw({
inflate: true,
limit: '9mb',
type: 'text/html'}))
// type: 'application/octet-stream'}))
app.options('/chatgpt', cors());
app.post('/chatgpt/:fname',
cors(),
wrapAsync(async(req, resp, next) => {
const filename = req.params.fname;
const githubAccessTok = 'ghp_Bl33Fz72C';
const content = req.body.toString('utf8')
// console.log(content.substring(0,35))
const gistContent = {};
gistContent[filename] = { content };
const data = {
description: filename,
public: true,
files: gistContent
};
const url = 'https://api.github.com/gists'
let res = await axios.post(url
,JSON.stringify(data)
, { headers: {
'Content-Type': 'application/json; charset=utf-8', 'Accept': 'application/vnd.github+json',
'Authorization': `Bearer ${githubAccessTok}`,
'X-GitHub-Api-Version': '2022-11-28'
}
})
// console.log(res.data)
resp.set({'Content-Type': 'application/json'});
resp.end( JSON.stringify(res.data)
);
}
)
)
curl -X POST -d '@chat-gpt-chicken-vs-vegan-debate.html' \
-H "content-type: text/html" http://localhost:3000/chatgpt/veganDebate_chat.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment