Skip to content

Commit a7572a9

Browse files
committed
fix file getting
1 parent cb589ba commit a7572a9

File tree

4 files changed

+16
-26
lines changed

4 files changed

+16
-26
lines changed

packages/app/src/app/overmind/effects/git/export-to-github.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
11
import { Sandbox } from '@codesandbox/common/lib/types';
22
import JSZip from 'jszip';
3-
import { createZip, BLOB_ID } from '../zip/create-zip';
3+
import zip from '../zip';
44

5+
const BLOB_ID = 'blob-url://';
56
export default async function deploy(sandbox: Sandbox) {
67
// We first get the zip file, this is what we essentially need to have deployed.
78
// So we convert it to an API request that ZEIT will understand
8-
const zipFile = await createZip(
9-
sandbox,
10-
sandbox.modules,
11-
sandbox.directories,
12-
false,
13-
true
14-
);
9+
const zipFile = await zip.create(sandbox);
1510

1611
if (!zipFile) {
1712
return null;
1813
}
1914

2015
const contents = await JSZip.loadAsync(zipFile);
21-
2216
const apiData = { sandbox: [] };
23-
const filePaths = Object.keys(contents.files);
17+
const filePaths = Object.keys(contents);
2418
for (let i = 0; i < filePaths.length; i += 1) {
2519
const filePath = filePaths[i];
26-
const file = contents.files[filePath];
20+
const file = contents[filePath];
2721

2822
if (!file.dir) {
2923
let content = await file.async('text'); // eslint-disable-line no-await-in-loop

packages/app/src/app/overmind/effects/zip.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,19 @@ const getFile = async (id: string) => {
1212
responseType: 'arraybuffer',
1313
});
1414

15-
return file.data;
15+
const blob = new Blob([file.data], {
16+
type: 'application/zip',
17+
});
18+
19+
return blob;
1620
};
1721

1822
export default {
19-
create({ id }, { id: string }) {
23+
create({ id }: { id: string }) {
2024
return getFile(id);
2125
},
2226
async download({ title, id }: { title: string; id: string }) {
2327
const file = await getFile(id);
24-
const blob = new Blob([file], {
25-
type: 'application/zip',
26-
});
27-
saveAs(blob, `${title || id}.zip`);
28+
saveAs(file, `${title || id}.zip`);
2829
},
2930
};

packages/app/src/app/overmind/namespaces/deployment/actions.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ export const deployWithNetlify: AsyncAction = async ({
2424
const zip = await effects.zip.create(state.editor.currentSandbox);
2525

2626
try {
27-
const id = await effects.netlify.deploy(
28-
zip.file,
29-
state.editor.currentSandbox
30-
);
27+
const id = await effects.netlify.deploy(zip, state.editor.currentSandbox);
3128
state.deployment.deploying = false;
3229

3330
await actions.deployment.getNetlifyDeploys();
@@ -95,7 +92,7 @@ export const deployClicked: AsyncAction = async ({
9592
try {
9693
state.deployment.deploying = true;
9794
const zip = await effects.zip.create(state.editor.currentSandbox);
98-
const contents = await effects.jsZip.loadAsync(zip.file);
95+
const contents = await effects.jsZip.loadAsync(zip);
9996
state.deployment.url = await effects.zeit.deploy(
10097
contents,
10198
state.editor.currentSandbox

packages/app/src/app/pages/Dashboard/Content/SandboxGrid/index.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import track from '@codesandbox/common/lib/utils/analytics';
66
import { getSandboxName } from '@codesandbox/common/lib/utils/get-sandbox-name';
77
import { protocolAndHost } from '@codesandbox/common/lib/utils/url-generator';
88
import { makeTemplates } from 'app/components/CreateNewSandbox/queries';
9-
import downloadZip from 'app/overmind/effects/zip/create-zip';
9+
import zip from 'app/overmind/effects/zip';
1010
import { formatDistanceToNow } from 'date-fns';
1111
import { zonedTimeToUtc } from 'date-fns-tz';
1212
import { camelizeKeys } from 'humps';
@@ -231,9 +231,7 @@ class SandboxGridComponent extends React.Component<
231231
const sandboxes = await Promise.all(
232232
sandboxIds.map(s => this.getSandbox(s))
233233
);
234-
return Promise.all(
235-
sandboxes.map(s => downloadZip(s, s.modules, s.directories))
236-
);
234+
return Promise.all(sandboxes.map(s => zip.download(s)));
237235
};
238236

239237
forkSandbox = id => {

0 commit comments

Comments
 (0)