use pastry for createPaste
Summary: Moving from `arc` to `pastry` to create Pastes. arc paste is deprecated and throws errors sometimes. Pastry seems to be the tool of choice now and has a nicer API anyways. Reviewed By: passy Differential Revision: D10302075 fbshipit-source-id: a846adf3768a2adf5c7ff73dc89b18c1e9169ac0
This commit is contained in:
committed by
Facebook Github Bot
parent
8d7774c409
commit
faf521aa87
@@ -7,64 +7,44 @@
|
||||
|
||||
import child_process from 'child_process';
|
||||
import {clipboard, shell} from 'electron';
|
||||
import JSONStream from 'JSONStream';
|
||||
|
||||
type PasteResponse =
|
||||
| string
|
||||
| {
|
||||
id: number,
|
||||
objectName: string,
|
||||
phid: string,
|
||||
authorPHID: string,
|
||||
filePHID: string,
|
||||
title: string,
|
||||
dateCreated: number,
|
||||
language: string,
|
||||
uri: string,
|
||||
parentPHID: ?number,
|
||||
content: string,
|
||||
}
|
||||
| {
|
||||
type: 'error',
|
||||
message: string,
|
||||
createdPaste: {
|
||||
id: number,
|
||||
url: string,
|
||||
},
|
||||
};
|
||||
|
||||
export default function createPaste(input: string): Promise<?string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const arc = '/opt/facebook/bin/arc';
|
||||
const child = child_process.spawn(arc, [
|
||||
'--conduit-uri=https://phabricator.intern.facebook.com/api/',
|
||||
'paste',
|
||||
'--json',
|
||||
]);
|
||||
const child = child_process.spawn('pastry', ['--json']);
|
||||
|
||||
let lastMessage: ?PasteResponse;
|
||||
|
||||
child.stdout
|
||||
.pipe(JSONStream.parse([true]))
|
||||
.on('data', (data: PasteResponse) => {
|
||||
if (typeof data === 'string' && lastMessage === 'error') {
|
||||
new window.Notification('Failed to create paste', {
|
||||
body: data,
|
||||
});
|
||||
reject(data);
|
||||
} else if (typeof data === 'object' && data.createdPaste) {
|
||||
const {url, id} = data.createdPaste;
|
||||
clipboard.writeText(url);
|
||||
const notification = new window.Notification(`Paste P${id} created`, {
|
||||
body: 'URL copied to clipboard',
|
||||
});
|
||||
notification.onclick = () => shell.openExternal(url);
|
||||
resolve(url);
|
||||
}
|
||||
lastMessage = data;
|
||||
});
|
||||
|
||||
child.stdin.write(input);
|
||||
child.stdin.end();
|
||||
let response = '';
|
||||
child.stdout.on('data', (data: Buffer) => {
|
||||
response += data.toString();
|
||||
});
|
||||
child.stdout.on('end', (data: Buffer) => {
|
||||
const result: PasteResponse = JSON.parse(response || 'null');
|
||||
|
||||
if (!result) {
|
||||
new window.Notification('Failed to create paste', {
|
||||
body: `Does ${arc} exist and is executable?`,
|
||||
});
|
||||
} else if (result.type === 'error') {
|
||||
new window.Notification('Failed to create paste', {
|
||||
body: result.message != null ? result.message : '',
|
||||
});
|
||||
reject(result);
|
||||
} else {
|
||||
clipboard.writeText(result.uri);
|
||||
const notification = new window.Notification(
|
||||
`Paste ${result.objectName} created`,
|
||||
{
|
||||
body: 'URL copied to clipboard',
|
||||
},
|
||||
);
|
||||
notification.onclick = () => shell.openExternal(result.uri);
|
||||
resolve(result.uri);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user