[Bbs2ch-cvs 35] CVS update: bbs2chreader/content/bbs2chreader/test

Back to archive index

flyson flyso****@users*****
2005年 10月 27日 (木) 22:56:17 JST


Index: bbs2chreader/content/bbs2chreader/test/thread-test.js
diff -u bbs2chreader/content/bbs2chreader/test/thread-test.js:1.2 bbs2chreader/content/bbs2chreader/test/thread-test.js:1.3
--- bbs2chreader/content/bbs2chreader/test/thread-test.js:1.2	Sun Oct 23 21:14:10 2005
+++ bbs2chreader/content/bbs2chreader/test/thread-test.js	Thu Oct 27 22:56:17 2005
@@ -96,33 +96,6 @@
 		return this._type;
 	},
 
-	get datURL(){
-		if(!this._datURL){
-			var datURLSpec = this.boardURL.resolve("dat/" + this.datID + ".dat");
-			this._datURL = this._ioService.newURI(datURLSpec, null, null)
-						.QueryInterface(Components.interfaces.nsIURL);
-		}
-		return this._datURL;
-	},
-
-	get datFile(){
-		return this._datFile;
-	},
-
-	get idxFile(){
-		return this._idxFile;
-	},
-
-	get datID(){
-		if(!this._datID)
-			this._datID = this.threadURL.directory.match(/\/(\d{9,10})/) ? RegExp.$1 : null;
-		return this._datID;
-	},
-
-	get title(){
-		return this._title;
-	},
-
 	get optionsStart(){
 	  return (this.threadURL.fileName.match(/(\d+)\-/)) ? RegExp.$1 : null;
 	},
@@ -152,38 +125,22 @@
 						.QueryInterface(Components.interfaces.nsIURL);
 		this._boardURL = this._bbs2chService.getBoardURL(this.threadURL.spec);
 		this._type = this._bbs2chService.getBoardType(this.threadURL.spec);
-		this._datFile = this._bbs2chService.getLogFileAtURL(
-								this.boardURL.resolve(this.datID + ".dat"));
-		this._idxFile = this._bbs2chService.getLogFileAtURL(
-								this.boardURL.resolve(this.datID + ".idx"));
-
-			// idx ファイルからタイトル等を取得
-		if(this.idxFile.exists()){
-			var idxContent =  this._bbs2chService.readFile(this.idxFile.path);
-
-			this._title = idxContent.match(/^title=(.+)/m) ? RegExp.$1 : "";
-			this._lineCount = idxContent.match(/^lineCount=(.+)/m) ? Number(RegExp.$1) : 0;
-			this._lastModified = idxContent.match(/^lastModified=(.+)/m) ? RegExp.$1 : "";
-			this._eTag = idxContent.match(/^etag=(.+)/m) ? RegExp.$1 : "";
-		}else{
-			this._title = "";
-			this._lineCount = 0;
-			this._lastModified = "";
-			this._eTag = "";
-		}
+		
+		this.dat = new b2rDat();
+		this.dat.init(this.threadURL, this.boardURL, this._type);
+		
 
 		this.requestRespond("Thread URL    : " + this.threadURL.spec + "\n");
 		this.requestRespond("Board URL     : " + this.boardURL.spec + "\n");
-		this.requestRespond("DAT URL       : " + this.datURL.spec + "\n");
 		this.requestRespond("Type          : " + this.type + "\n");
-		this.requestRespond("DAT ID        : " + this.datID + "\n");
-		this.requestRespond("DAT File      : " + this.datFile.path + "\n");
-		this.requestRespond("IDX File      : " + this.idxFile.path + "\n");
+		this.requestRespond("DAT URL       : " + this.dat.datURL.spec + "\n");
+		this.requestRespond("DAT ID        : " + this.dat.id + "\n");
+		this.requestRespond("DAT File      : " + this.dat.datFile.path + "\n");
+		this.requestRespond("IDX File      : " + this.dat.idxFile.path + "\n");
 		this.requestRespond("----- ----- -----\n");
-		this.requestRespond("Title         : " + this.title + "\n");
-		this.requestRespond("LineCount     : " + this._lineCount + "\n");
-		this.requestRespond("LastModified  : " + this._lastModified + "\n");
-		this.requestRespond("ETag          : " + this._eTag + "\n");
+		this.requestRespond("Title         : " + this.dat.title + "\n");
+		this.requestRespond("LineCount     : " + this.dat.lineCount + "\n");
+		this.requestRespond("LastModified  : " + this.dat.lastModified + "\n");
 		this.requestRespond("----- ----- -----\n");
 		this.requestRespond("URL Options \n");
 		this.requestRespond("  Start       : " + this.optionsStart + "\n");
@@ -191,11 +148,13 @@
 		this.requestRespond("  End         : " + this.optionsEnd + "\n");
 		this.requestRespond("  NoFirst     : " + this.optionsNoFirst + "\n");
 		this.requestRespond("----- ----- -----\n\n");
+
+		// this.requestEnd();
 		this.datDownload();
 	},
 	
 	datDownload: function(){
-		var httpChannel = this._ioService.newChannelFromURI(this.datURL)
+		var httpChannel = this._ioService.newChannelFromURI(this.dat.datURL)
 					.QueryInterface(Components.interfaces.nsIHttpChannel);
 		httpChannel.requestMethod = "GET";
 		httpChannel.redirectionLimit = 0; // 302 等のリダイレクトを行わない
@@ -203,10 +162,10 @@
 		httpChannel.setRequestHeader("User-Agent", this._bbs2chService.userAgent, false);
 
 			// 差分GET
-		if(this.datFile.exists() && this._lastModified){
+		if(this.dat.datFile.exists() && this.dat.lastModified){
 			httpChannel.setRequestHeader("Accept-Encoding", "identity", false);
-			httpChannel.setRequestHeader("If-Modified-Since", this._lastModified, false);
-			httpChannel.setRequestHeader("Range", "bytes=" + this.datFile.fileSize + "-", false);
+			httpChannel.setRequestHeader("If-Modified-Since", this.dat.lastModified, false);
+			httpChannel.setRequestHeader("Range", "bytes=" + this.dat.datFile.fileSize + "-", false);
 		}
 
 		this.wrappedJSObject = this;
@@ -265,8 +224,8 @@
 
 			// DAT を 変換して書き出す
 		for(var i=0; i<datLines.length; i++){
-			this._lineCount++;
-			datLines[i] = this.lineCount +"\t:"+ datLines[i];
+			this.dat.lineCount++;
+			datLines[i] = this.dat.lineCount +"\t:"+ datLines[i];
 		}
 		this.requestRespond(datLines.join("\n"));
 
@@ -274,8 +233,7 @@
 
 	onStopRequest: function(aHttpChannel, aResponseText, aHttpStatus){
 		try{
-			this._lastModified = aHttpChannel.getResponseHeader("Last-Modified");
-			this._eTag = aHttpChannel.getResponseHeader("Etag");
+			this.dat.lastModified = aHttpChannel.getResponseHeader("Last-Modified");
 		}catch(ex){}
 
 		switch(aHttpStatus){
@@ -293,8 +251,8 @@
 		}
 
 		if(this._datBuffer){
-			this._lineCount++;
-			this._datBuffer = this.lineCount +"\t: "+ this._datBuffer;
+			this.dat.lineCount++;
+			this._datBuffer = this.dat.lineCount +"\t: "+ this._datBuffer;
 			this.requestRespond(this._datBuffer);
 		}
 
@@ -306,22 +264,16 @@
 	datSave: function(aDatContent){
 				// 書き込みのバッティングを避ける
 		var tmpLineCount = 0;
-		if(this.idxFile.exists()){
-			var idxContent = this._bbs2chService.readFile(this.idxFile.path);
+		if(this.dat.idxFile.exists()){
+			var idxContent = this._bbs2chService.readFile(this.dat.idxFile.path);
 			tmpLineCount = idxContent.match(/^lineCount=(.+)/m) ? parseInt(RegExp.$1) : 0;
 		}
-		if(this.lineCount > tmpLineCount){
-				// .dat の書き込み
-			this._bbs2chService.writeFile(this.datFile.path, aDatContent, true);
+		if(this.dat.lineCount > tmpLineCount){
+				// .dat の追記書き込み
+			this.dat.appendContent(aDatContent);
 
 				// .idx の書き込み
-			var idxContent = new Array();
-			if(this.title) idxContent.push("title=" + this.title);
-			if(this._lineCount) idxContent.push("lineCount=" + this._lineCount);
-			if(this._lastModified) idxContent.push("lastModified=" + this._lastModified);
-			if(this._eTag) idxContent.push("etag=" + this._eTag);
-			idxContent = idxContent.join("\n");
-			this._bbs2chService.writeFile(this.idxFile.path, idxContent, false);
+			this.dat.flushIdx();
 		}
 	}
 }
@@ -337,14 +289,6 @@
 
 b2rJbbsThread.prototype = {
 
-	get datURL(){
-		if(!this._datURL){
-			var datURLSpec = this.threadURL.resolve("./").replace("read.cgi", "rawmode.cgi");
-			this._datURL = this._ioService.newURI(datURLSpec, null, null)
-						.QueryInterface(Components.interfaces.nsIURL);
-		}
-		return this._datURL;
-	},
 
 }
 b2rJbbsThread.prototype.__proto__ = b2r2chThread.prototype;


bbs2ch-cvs メーリングリストの案内
Back to archive index