diff --git a/README.md b/README.md
index a32eec4..e25fc20 100644
--- a/README.md
+++ b/README.md
@@ -80,9 +80,9 @@ Thanks goes out to all these wonderful people ([emoji key](https://github.com/ke
-| [
briandennis](https://github.com/briandennis)
[π»](https://github.com/dawnlabs/carbon/commits?author=briandennis "Code") [π](https://github.com/dawnlabs/carbon/commits?author=briandennis "Documentation") [π](#infra-briandennis "Infrastructure (Hosting, Build-Tools, etc)") [π](#review-briandennis "Reviewed Pull Requests") | [
mfix22](https://github.com/mfix22)
[π¬](#question-mfix22 "Answering Questions") [π»](https://github.com/dawnlabs/carbon/commits?author=mfix22 "Code") [π€](#ideas-mfix22 "Ideas, Planning, & Feedback") | [
jakedex](https://github.com/jakedex)
[π¬](#question-jakedex "Answering Questions") [π»](https://github.com/dawnlabs/carbon/commits?author=jakedex "Code") [π¨](#design-jakedex "Design") [πΉ](#video-jakedex "Videos") | [
andrewda](https://github.com/andrewda)
[π¬](#question-andrewda "Answering Questions") [π»](https://github.com/dawnlabs/carbon/commits?author=andrewda "Code") [π](https://github.com/dawnlabs/carbon/issues?q=author%3Aandrewda "Bug reports") [π](#review-andrewda "Reviewed Pull Requests") | [
yeskunall](https://github.com/yeskunall)
[π»](https://github.com/dawnlabs/carbon/commits?author=yeskunall "Code") [π](https://github.com/dawnlabs/carbon/commits?author=yeskunall "Documentation") [π§](#tool-yeskunall "Tools") [π](https://github.com/dawnlabs/carbon/issues?q=author%3Ayeskunall "Bug reports") | [
stoshfabricius](https://github.com/stoshfabricius)
[π»](https://github.com/dawnlabs/carbon/commits?author=stoshfabricius "Code") | [
jkling38](https://github.com/jkling38)
[π](https://github.com/dawnlabs/carbon/commits?author=jkling38 "Documentation") |
+| [
briandennis](https://github.com/briandennis)
[π»](/dawnlabs/carbon/commits?author=briandennis "Code") [π](/dawnlabs/carbon/commits?author=briandennis "Documentation") [π](#infra-briandennis "Infrastructure (Hosting, Build-Tools, etc)") [π](#review-briandennis "Reviewed Pull Requests") | [
mfix22](https://github.com/mfix22)
[π¬](#question-mfix22 "Answering Questions") [π»](/dawnlabs/carbon/commits?author=mfix22 "Code") [π€](#ideas-mfix22 "Ideas, Planning, & Feedback") | [
jakedex](https://github.com/jakedex)
[π¬](#question-jakedex "Answering Questions") [π»](/dawnlabs/carbon/commits?author=jakedex "Code") [π¨](#design-jakedex "Design") [πΉ](#video-jakedex "Videos") | [
andrewda](https://github.com/andrewda)
[π¬](#question-andrewda "Answering Questions") [π»](/dawnlabs/carbon/commits?author=andrewda "Code") [π](/dawnlabs/carbon/issues?q=author%3Aandrewda "Bug reports") [π](#review-andrewda "Reviewed Pull Requests") | [
yeskunall](https://github.com/yeskunall)
[π»](/dawnlabs/carbon/commits?author=yeskunall "Code") [π](/dawnlabs/carbon/commits?author=yeskunall "Documentation") [π§](#tool-yeskunall "Tools") [π](/dawnlabs/carbon/issues?q=author%3Ayeskunall "Bug reports") | [
stoshfabricius](https://github.com/stoshfabricius)
[π»](/dawnlabs/carbon/commits?author=stoshfabricius "Code") | [
jkling38](https://github.com/jkling38)
[π](/dawnlabs/carbon/commits?author=jkling38 "Documentation") |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
-| [
otobrglez](https://github.com/otobrglez)
[π»](https://github.com/dawnlabs/carbon/commits?author=otobrglez "Code") | [
darahak](https://github.com/darahak)
[π](https://github.com/dawnlabs/carbon/commits?author=darahak "Documentation") | [
dom96](https://github.com/dom96)
[π»](https://github.com/dawnlabs/carbon/commits?author=dom96 "Code") | [
elrumordelaluz](https://github.com/elrumordelaluz)
[π»](https://github.com/dawnlabs/carbon/commits?author=elrumordelaluz "Code") | [
cjb](https://github.com/cjb)
[π»](https://github.com/dawnlabs/carbon/commits?author=cjb "Code") | [
Krzysztof-Cieslak](https://github.com/Krzysztof-Cieslak)
[π»](https://github.com/dawnlabs/carbon/commits?author=Krzysztof-Cieslak "Code") | [
fernahh](https://github.com/fernahh)
[π](https://github.com/dawnlabs/carbon/commits?author=fernahh "Documentation") |
-| [
g3r4n](https://github.com/g3r4n)
[π»](https://github.com/dawnlabs/carbon/commits?author=g3r4n "Code") | [
Mat Gadd](http://drarok.com/)
[π](https://github.com/dawnlabs/carbon/issues?q=author%3ADrarok "Bug reports") [π»](https://github.com/dawnlabs/carbon/commits?author=Drarok "Code") | [
Brad Davies](https://bradlab.co.uk)
[π](https://github.com/dawnlabs/carbon/issues?q=author%3Avarbrad "Bug reports") [π»](https://github.com/dawnlabs/carbon/commits?author=varbrad "Code") | [
Rafael CΓ’mara](http://www.rafaelcamaram.com/)
[π»](https://github.com/dawnlabs/carbon/commits?author=rafaelcamaram "Code") | [
Gleb Bahmutov](https://glebbahmutov.com/)
[β οΈ](https://github.com/dawnlabs/carbon/commits?author=bahmutov "Tests") [π§](#tool-bahmutov "Tools") | [
IvΓ‘n MunguΓa](https://ivan-munguia.netlify.com)
[π»](https://github.com/dawnlabs/carbon/commits?author=warborn "Code") | [
Dillon Mulroy](https://dillonmulroy.com)
[π»](https://github.com/dawnlabs/carbon/commits?author=dmmulroy "Code") |
-| [
Nihad Abbasov](https://github.com/NARKOZ)
[π»](https://github.com/dawnlabs/carbon/commits?author=NARKOZ "Code") | [
Hugo Torzuoli](https://torzuolih.github.io)
[π](https://github.com/dawnlabs/carbon/commits?author=TorzuoliH "Documentation") | [
Bruno C. Couto](https://github.com/bruno02221)
[π»](https://github.com/dawnlabs/carbon/commits?author=bruno02221 "Code") | [
Mark Molnar](https://github.com/molnarmark)
[π»](https://github.com/dawnlabs/carbon/commits?author=molnarmark "Code") | [
Takahiko Inayama](https://www.behance.net/tetra2000)
[π»](https://github.com/dawnlabs/carbon/commits?author=TETRA2000 "Code") | [
François Martin](https://github.com/martinfrancois)
[π»](https://github.com/dawnlabs/carbon/commits?author=martinfrancois "Code") |
+| [
otobrglez](https://github.com/otobrglez)
[π»](/dawnlabs/carbon/commits?author=otobrglez "Code") | [
darahak](https://github.com/darahak)
[π](/dawnlabs/carbon/commits?author=darahak "Documentation") | [
dom96](https://github.com/dom96)
[π»](/dawnlabs/carbon/commits?author=dom96 "Code") | [
elrumordelaluz](https://github.com/elrumordelaluz)
[π»](/dawnlabs/carbon/commits?author=elrumordelaluz "Code") | [
cjb](https://github.com/cjb)
[π»](/dawnlabs/carbon/commits?author=cjb "Code") | [
Krzysztof-Cieslak](https://github.com/Krzysztof-Cieslak)
[π»](/dawnlabs/carbon/commits?author=Krzysztof-Cieslak "Code") | [
fernahh](https://github.com/fernahh)
[π](/dawnlabs/carbon/commits?author=fernahh "Documentation") |
+| [
g3r4n](https://github.com/g3r4n)
[π»](/dawnlabs/carbon/commits?author=g3r4n "Code") | [
Mat Gadd](http://drarok.com/)
[π](/dawnlabs/carbon/issues?q=author%3ADrarok "Bug reports") [π»](/dawnlabs/carbon/commits?author=Drarok "Code") | [
Brad Davies](https://bradlab.co.uk)
[π](/dawnlabs/carbon/issues?q=author%3Avarbrad "Bug reports") [π»](/dawnlabs/carbon/commits?author=varbrad "Code") | [
Rafael CΓ’mara](http://www.rafaelcamaram.com/)
[π»](/dawnlabs/carbon/commits?author=rafaelcamaram "Code") | [
Gleb Bahmutov](https://glebbahmutov.com/)
[β οΈ](/dawnlabs/carbon/commits?author=bahmutov "Tests") [π§](#tool-bahmutov "Tools") | [
IvΓ‘n MunguΓa](https://ivan-munguia.netlify.com)
[π»](/dawnlabs/carbon/commits?author=warborn "Code") | [
Dillon Mulroy](https://dillonmulroy.com)
[π»](/dawnlabs/carbon/commits?author=dmmulroy "Code") |
+| [
Nihad Abbasov](https://github.com/NARKOZ)
[π»](/dawnlabs/carbon/commits?author=NARKOZ "Code") | [
Hugo Torzuoli](https://torzuolih.github.io)
[π](/dawnlabs/carbon/commits?author=TorzuoliH "Documentation") | [
Bruno C. Couto](https://github.com/bruno02221)
[π»](/dawnlabs/carbon/commits?author=bruno02221 "Code") | [
Mark Molnar](https://github.com/molnarmark)
[π»](/dawnlabs/carbon/commits?author=molnarmark "Code") | [
Takahiko Inayama](https://www.behance.net/tetra2000)
[π»](/dawnlabs/carbon/commits?author=TETRA2000 "Code") | [
François Martin](https://github.com/martinfrancois)
[π»](/dawnlabs/carbon/commits?author=martinfrancois "Code") |
diff --git a/handlers/image.js b/handlers/image.js
index 90ffe9a..14d914e 100644
--- a/handlers/image.js
+++ b/handlers/image.js
@@ -1,11 +1,13 @@
+const port = parseInt(process.env.PORT, 10) || 3000
+
module.exports = browser => async (req, res) => {
let page = await browser.newPage()
- let url = req.body.url
+ let state = req.body.state
- if (!url) res.status(400).send()
+ if (!state) res.status(400).send()
try {
- await page.goto(url)
+ await page.goto(`http://localhost:${port}?state=${state}`)
await page.addScriptTag({ path: `./lib/customDomToImage.js` })
const targetElement = await page.$('#export-container')
diff --git a/lib/api.js b/lib/api.js
index 55b57f0..7a37b8a 100644
--- a/lib/api.js
+++ b/lib/api.js
@@ -26,8 +26,8 @@ async function tweet(encodedImage) {
.catch(checkIfRateLimited)
}
-async function image(url) {
- return axios.post(`${DOMAIN}/image`, { url }).then(res => res.data.dataUrl)
+async function image(state) {
+ return axios.post(`${DOMAIN}/image`, { state }).then(res => res.data.dataUrl)
}
const getGist = uid => {
diff --git a/lib/routing.js b/lib/routing.js
index 369212f..306a79f 100644
--- a/lib/routing.js
+++ b/lib/routing.js
@@ -46,8 +46,7 @@ const reverseMappings = mappings.map(mapping =>
})
)
-
-const serializeState = state => {
+export const serializeState = state => {
const stateString = encodeURIComponent(JSON.stringify(state))
return typeof window !== 'undefined'
@@ -55,7 +54,7 @@ const serializeState = state => {
: Buffer.from(stateString).toString('base64')
}
-const deserializeState = serializedState => {
+export const deserializeState = serializedState => {
let stateString
if (typeof window !== 'undefined') {
stateString = atob(serializedState)
diff --git a/pages/editor.js b/pages/editor.js
index 09350b1..eb9314f 100644
--- a/pages/editor.js
+++ b/pages/editor.js
@@ -33,7 +33,7 @@ import {
DEFAULT_BG_COLOR,
DEFAULT_SETTINGS
} from '../lib/constants'
-import { getQueryStringState, updateQueryString } from '../lib/routing'
+import { getQueryStringState, updateQueryString, serializeState } from '../lib/routing'
import { getState, saveState } from '../lib/util'
const removeQueryString = str => {
@@ -79,6 +79,7 @@ class Editor extends React.Component {
this.updateTitleBar = this.updateTitleBar.bind(this)
this.updateAspectRatio = this.updateAspectRatio.bind(this)
this.resetDefaultSettings = this.resetDefaultSettings.bind(this)
+ this.getCarbonImage = this.getCarbonImage.bind(this)
}
componentDidMount() {
@@ -104,12 +105,13 @@ class Editor extends React.Component {
//if safari, get image from api
if (
navigator.userAgent.indexOf('Safari') != -1 &&
- navigator.userAgent.indexOf('Chrome') == -1
+ navigator.userAgent.indexOf('Chrome') == -1 &&
+ format === 'png'
) {
- return api.image(window.location.href)
+ const encodedState = serializeState(this.state)
+ return api.image(encodedState)
}
-
const node = document.getElementById('export-container')
const exportSize = (EXPORT_SIZES_HASH[this.state.exportSize] || DEFAULT_EXPORT_SIZE).value