 
 	upload: (url, form, callback) -> # support auto-relogin relavant url
 		url = @url url
-		if not @id # TODO: check login properly
-			@auto_login (result) =>
-				@http_upload url, form, callback
-		else
+		@login_check =>
+			# TODO: check response for session timeout
 			@http_upload url, form, callback
 
 	init: (callback) ->


	add_bt_task_by_info_hash: (hash, callback) ->
		hash = hash.toUpperCase()
		# TODO: check session and @id
		if @id
			url = "http://dynamic.cloud.vip.xunlei.com/interface/get_torrent?userid=#{@id}&infoid=#{hash}"
			@add_bt_task_by_query_url url, callback
		else
			# TODO: ineffient, should try login_enrich_cookie
			@auto_login =>
				url = "http://dynamic.cloud.vip.xunlei.com/interface/get_torrent?userid=#{@id}&infoid=#{hash}"
				@add_bt_task_by_query_url url, callback

	add_magnet_task: (url, callback) ->
		# TODO: check session and @id
#		@add_bt_task_by_query_url url, callback
		if @id
			@add_bt_task_by_query_url url, callback
		else
			@auto_login =>
				@add_bt_task_by_query_url url, callback

	add_task: (url, callback) ->
		throw new Error("Not Implemented: add_task")



	commit_bt_task: ({info_hash, name, size, files}, callback) ->
		@with_id (id) =>
			form =
				uid: id
				btname: name
				cid: info_hash
				tsize: size
				findex: (f['id']+'_' for f in files).join('')
				size: (f['size']+'_' for f in files).join('')
				from: '0'
			jsonp = "jsonp#{current_timestamp()}"
			commit_url = "/interface/bt_task_commit?callback=#{jsonp}"
			@post commit_url, form, ({text}) ->
				if text.match "^#{jsonp}\(.*\)"
					callback ok: true, reason: 'BT task created', info_hash: info_hash
				else
					callback ok: false, reason: 'Failed be parse bt result', response: text

	add_bt_task_by_blob: (blob, callback) ->
		@upload_torrent_file_by_blob blob, (result) =>
