示例#1
0
文件: server.js 项目: kapetan/dribler
	request.match(function(match, preview) {
		var session = request.session;
		var data = request.body;

		var onsession = function(reddit) {
			preview.renderMarkdown(function(err, content) {
				if(err) return response.error(500, err);

				var thread = {
					captcha: {
						id: data.thread_captcha_id,
						solution: data.thread_captcha_solution
					},
					url: data.thread_url,
					title: data.thread_title,
					subreddit: data.thread_subreddit,
					text: content,
					events: preview.query
				};

				var onfinish = function(err, createdThread) {
					if(err) return response.error(500, err);

					var threadStream = new ThreadStream(match, createdThread, reddit);
					createdThread.stream = threadStream;

					match.pipe(threadStream);
					threadStream.on('error', function() {
						match.unpipe(threadStream);
						delete threads[createdThread.id];
					});

					response.session = reddit.session;
					response.redirect('/matches/reddit/' + match.id);
				};

				if(thread.url) match.createThreadUsingUrl(reddit, thread, onfinish)
				else match.createThread(reddit, thread, onfinish);
			});
		};

		if(data.user_username && data.user_password) {
			reddit({ username: data.user_username, password: data.user_password }, function(err, reddit) {
				if(err) return response.error(400, err);
				onsession(reddit);
			});
		} else if(session) {
			onsession(reddit(session));
		} else {
			response.error(400, new Error('No reddit session'));
		}
	});
示例#2
0
文件: server.js 项目: kapetan/dribler
	request.on('form', function(data) {
		reddit({ username: data.user_username, password: data.user_password }, function(err, reddit) {
			if(err) return response.error(400, err);

			response.session = reddit.session;
			response.redirect('/matches/reddit/' + request.params.id);
		});
	});
示例#3
0
文件: server.js 项目: kapetan/dribler
		preview.renderMarkdown(function(err, content) {
			if(err) return response.error(500, err);

			match.updateThread(request.params.thread, reddit(session), content, function(err) {
				if(err) return response.error(500, err);
				response.redirect('/matches/reddit/' + match.id);
			});
		});