Skip to content

Commit b475926

Browse files
committed
Fix encoding issues when using Copy button
Previously the Copy button was using the GitHub API to fetch the file contents in base64 form, and then decoding that. This caused unicode symbols to be incorrectly encoded (such as the copyright symbol in several files). This commit changes the Copy button to instead fetch the file directly, which fixes the encoding issue.
1 parent 6b31acd commit b475926

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

src/components/common/CopyFileButton.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState } from 'react'
22
import styled from '@emotion/styled'
33
import { Button, Popover } from 'antd'
4-
import { getFileApiURL, replaceWithProvidedAppName } from '../../utils'
4+
import { getBinaryFileURL, replaceWithProvidedAppName } from '../../utils'
55
import { CopyOutlined } from '@ant-design/icons'
66

77
const popoverContentOpts = {
@@ -16,9 +16,8 @@ const CopyFileButton = styled(
1616
)
1717

1818
const fetchContent = () =>
19-
fetch(getFileApiURL({ packageName, version, path }))
20-
.then((response) => response.json())
21-
.then((json) => window.atob(json.content))
19+
fetch(getBinaryFileURL({ packageName, version, path }))
20+
.then((response) => response.text())
2221
.then((content) => replaceWithProvidedAppName(content, appName))
2322

2423
const copyContent = () => {

src/utils.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,9 @@ const getBranch = ({ packageName, language, version }) =>
4444
export const getBinaryFileURL = ({ packageName, language, version, path }) => {
4545
const branch = getBranch({ packageName, language, version })
4646

47-
return `https://github.com/${getRNDiffRepository({
48-
packageName,
49-
})}/raw/release/${branch}/${path}`
50-
}
51-
52-
export const getFileApiURL = ({ packageName, language, version, path }) => {
53-
const branch = getBranch({ packageName, language, version })
54-
55-
return `https://api.github.com/repos/${getRNDiffRepository({
47+
return `https://raw.githubusercontent.com/${getRNDiffRepository({
5648
packageName,
57-
})}/contents/${path}?ref=${encodeURIComponent(`release/${branch}`)}`
49+
})}/release/${branch}/${path}`
5850
}
5951

6052
export const removeAppPathPrefix = (path, appName) =>

0 commit comments

Comments
 (0)