Skip to content

Commit

Permalink
support weird filename
Browse files Browse the repository at this point in the history
  • Loading branch information
athanhcong committed Jul 23, 2013
1 parent eb09b5d commit f561c19
Show file tree
Hide file tree
Showing 16 changed files with 864 additions and 13 deletions.
5 changes: 5 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -843,3 +843,8 @@ app.get('/me', function(req, res){
server.listen(config.serverPort, function(){
console.log("Express server listening on port " + config.serverPort)
})


process.on('uncaughtException', function(err) {
console.error(err.stack);
});
12 changes: 9 additions & 3 deletions lib/github/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ app.filenameForJekyllPost = filenameForJekyllPost = function(user, note) {
// var date = new Date();

// http://stackoverflow.com/a/2013332/192800
var titleFilename = title.toLowerCase().split(' ').join('-');
var titleFilename = safeFileName(title);
var filename = date.getUTCFullYear() + '-' + (date.getUTCMonth() + 1).pad(2) + '-' + date.getUTCDate().pad(2) + '-' + titleFilename;

console.log(date.getUTCFullYear());
Expand Down Expand Up @@ -474,6 +474,12 @@ app.contentInMarkdown = contentInMarkdown = function(user, evernoteNote, callbac
}


var safeFileName = function(string) {
var safeString = string.replace(/[^A-Za-z 0-9]*/g, '').trim();
safeString = safeString.toLowerCase().split(' ').join('-');
return safeString;
}

var uploadAResource = function (user, note, evernoteResource, callback) {
var noteStore = EvernoteLib.Client(user.evernote.oauthAccessToken).getNoteStore();

Expand All @@ -499,7 +505,7 @@ var uploadAResource = function (user, note, evernoteResource, callback) {
console.log('Repo: ' + repo.name + " Token: " + repo.client.token);


var resourceFilename = evernoteResource.attributes.fileName.toLowerCase().split(' ').join('-');
var resourceFilename = safeFileName(evernoteResource.attributes.fileName | evernoteResource.guid);
var path = "images/" + note.guid + "/"
// + new Date().getTime() + "/"
+ resourceFilename;
Expand Down Expand Up @@ -603,7 +609,7 @@ var uploadResources = function(user, note, callback) {
console.log("Finish uploadResourceIfNeeded: " + resource.github.file.path);

var githubUrl = "/" + resource.github.file.path;
uploadedResources[resource.evernoteGuid] = githubUrl;
uploadedResources[resource.evernoteGuid] = githubUrl;
} else {
console.log("Finish uploadResourceIfNeeded: ERROR: " + error + "DATA: " + JSON.stringify(resource));
};
Expand Down
32 changes: 23 additions & 9 deletions lib/tumblr/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var app = module.exports = express()



var Tumblr = require('tumblrwks');
var Tumblr = require('./tumblrwks');
var EvernoteLib = require('../evernote');

var url = require('url');
Expand All @@ -22,7 +22,6 @@ config.tumblrConsumerSecret = 'FhbEZ44CV6R7JXhFKT0RZUQM4CjrqvFi1ikdlGZCehMHHMkbT

//// Authentication


// Passport session setup.
// To support persistent login sessions, Passport needs to be able to
// serialize users into and deserialize users out of the session. Typically,
Expand Down Expand Up @@ -98,7 +97,6 @@ app.get('/tumblr/authentication/callback',
console.log(blog.host);
}


var tumblrUserUpdate = {
'tumblr.user' : tumblrUser
, 'tumblr.oauthAccessToken' : oauthAccessToken
Expand Down Expand Up @@ -237,11 +235,26 @@ app.updatePost = function(user, post, callback) {
// console.log("createPost in host: " + blogHost + " with oauth: " + JSON.stringify(oauth));


tumblr.post('/post/edit', post, function(json) {
console.log('Updated Post: ' + post.title + ' - Response: ' + JSON.stringify(json));

callback(null, json);
});
try {
tumblr.post('/post/edit', post, function(error, json) {
console.log('Updated Post: ' + post.title + ' - Response: ' + JSON.stringify(json));

if (error) {

} else {
callback(null, json);
}


});
} catch (e) {
console.log("entering catch block");
console.log(e);
} finally {
console.log("entering and leaving the finally block");
}


};

Expand Down Expand Up @@ -533,7 +546,6 @@ app.updatePostWithNoteAndId = function(user, tumblrPostId, evernoteNote, callbac

console.log("updatePostWithNote: " + evernoteNote.title + ' id: ' + tumblrPostId);


contentInMarkdown(user, evernoteNote, function(error, noteContent, tumblrPost) {

//check for tumblrPost
Expand All @@ -546,6 +558,9 @@ app.updatePostWithNoteAndId = function(user, tumblrPostId, evernoteNote, callbac
tumblrPostRequest.title = evernoteNote.title;
};


console.log(tumblrPostRequest);

return app.updatePost(user, tumblrPostRequest, function(error, tumblrPostResponse) {
//
// Save to database
Expand All @@ -564,7 +579,6 @@ app.updatePostWithNoteAndId = function(user, tumblrPostId, evernoteNote, callbac
, 'updated' : new Date()
};


app.db.posts.update({evernoteGuid: evernoteNote.guid}, {$set: post}, {upsert: true}, function(error) {
if (error) console.log('ERROR: ' + error);
console.log('saved + ' + evernoteNote.guid);
Expand Down
16 changes: 16 additions & 0 deletions lib/tumblr/tumblrwks/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.DS_Store
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz

pids
logs
results

node_modules
npm-debug.log
20 changes: 20 additions & 0 deletions lib/tumblr/tumblrwks/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(The MIT License)

Copyright (c) 2012 Fangzhou Ark Xu

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
105 changes: 105 additions & 0 deletions lib/tumblr/tumblrwks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
Tumblr Works!
=========

One node.js package lib talks to tumblr API v2 that really works.

## Installation

The recommended way is through the excellent [NPM](http://www.npmjs.org/):

$ npm install tumblrwks

## How to use

``` javascript
var Tumblr = require('tumblrwks');

/*
You can get the consumerKey and consumerSecret by registing a tumblr app: http://www.tumblr.com/oauth/apps
*/

var tumblr = new Tumblr(
{
consumerKey: 'your consumer key'
}//, "arktest.tumblr.com"
// specify the blog url now or the time you want to use
);

tumblr.get('/info', {hostname: 'arktest.tumblr.com'}, function(json){
console.log(json);
});

```

### Want to post blog? Need to specify more parameters!

``` javascript
var Tumblr = require('tumblrwks');

/*
For accessToken and accessSecret, user need to grant access of your app. I recommend to use: https://github.com/jaredhanson/passport-tumblr
*/

var tumblr = new Tumblr(
{
consumerKey: 'your consumer key',
consumerSecret: 'your consumer secret',
accessToken: 'access token',
accessSecret: 'access secret'
}, "arktest.tumblr.com"
// specify the blog url now or the time you want to use
);

tumblr.post('/post', {type: 'text', title: 'tumblrwkstesting', body: '<h3>should work!! </h3>'}, function(json){
console.log(json);
});

```

### Upload a photo from local disk

``` javascript
// upload local photo can work but can not upload multiple photos in a single blog
// most of the code for this are from ntumblr

// in general, tumblr api sucks
var photo = fs.readFileSync('./test/img/P1010486.jpg');

tumblr.post('/post', {type: 'photo', data: [photo]}, function(json){
console.log(json);
});

```


## Tests

$ mocha

You can find all the test cases in /test/all_test.js

The real test results are here: http://arktest.tumblr.com

## License

(The MIT License)

Copyright (c) 2012 Fangzhou Ark Xu

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

78 changes: 78 additions & 0 deletions lib/tumblr/tumblrwks/lib/custom-oauth.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions lib/tumblr/tumblrwks/lib/encode-image.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f561c19

Please sign in to comment.