Skip to content

Instantly share code, notes, and snippets.

@zhgqthomas
Last active June 30, 2017 15:07
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 zhgqthomas/d500c32f78859eddfa7f624f255368ba to your computer and use it in GitHub Desktop.
Save zhgqthomas/d500c32f78859eddfa7f624f255368ba to your computer and use it in GitHub Desktop.
Auto Draw 小程序版 LeanCloud 代理脚本
const https = require('https');
AV.Cloud.define('stencils', function (request, response) {
const options = {
hostname: 'www.autodraw.com',
path: '/assets/stencils.json',
port: 443,
method: 'GET',
headers: {
accept: '*/*'
}
};
const req = https.request(options, function (res) {
if (res.statusCode < 200 || res.statusCode > 299) {
res.on('error', function (error) {
response.error(new Error(error.message));
});
} else {
var output = '';
res.setEncoding('utf8');
res.on('data', function (chunk) {
output += chunk;
});
res.on('end', function () {
const payload = JSON.parse(output);
response.success(payload);
});
}
});
req.on('error', function (error) {
response.error(new Error(error.message))
});
req.end()
});
AV.Cloud.define('matchDraw', function (request, response) {
const options = {
hostname: 'inputtools.google.com',
path: '/request?ime=handwriting&app=autodraw&dbg=1&cs=1&oe=UTF-8',
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
};
const req = https.request(options, function (res) {
if (res.statusCode < 200 || res.statusCode > 299) {
res.on('error', function (error) {
response.error(new Error(error.message));
});
} else {
var payload = '';
res.setEncoding('utf8');
res.on('data', function (chunk) {
payload += chunk;
});
res.on('end', function () {
response.success(payload);
});
}
});
req.write(JSON.stringify(request.params));
req.on('error', function (error) {
response.error(new Error(error.message))
});
req.end()
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment