medialoder with storage
This commit is contained in:
@@ -1,5 +1,10 @@
|
|||||||
package haxework.net;
|
package haxework.net;
|
||||||
|
|
||||||
|
import haxework.net.callback.Callback;
|
||||||
|
import haxework.net.callback.ICallback;
|
||||||
|
import haxework.provider.Provider;
|
||||||
|
import haxework.storage.IStorage;
|
||||||
|
import flash.display.BitmapData;
|
||||||
import flash.events.ProgressEvent;
|
import flash.events.ProgressEvent;
|
||||||
import flash.system.Security;
|
import flash.system.Security;
|
||||||
import flash.system.SecurityDomain;
|
import flash.system.SecurityDomain;
|
||||||
@@ -17,6 +22,23 @@ class BaseMediaLoader<T> extends BaseLoader<T> {
|
|||||||
|
|
||||||
private var loader:Loader;
|
private var loader:Loader;
|
||||||
|
|
||||||
|
//ToDo: if storage use
|
||||||
|
override public function GET(url:String, data:Dynamic = null):ICallback<T> {
|
||||||
|
var storage:IStorage = Provider.get(IStorage);
|
||||||
|
return if (storage.exists(url)) {
|
||||||
|
fromBytes(storage.read(url));
|
||||||
|
} else {
|
||||||
|
var callback:ICallback<T> = new Callback<T>();
|
||||||
|
new BytesLoader().GET(url)
|
||||||
|
.success(function(data:ByteArray):Void {
|
||||||
|
storage.write(url, data);
|
||||||
|
fromBytes(data).glue(callback);
|
||||||
|
})
|
||||||
|
.fail(callback.callFail);
|
||||||
|
callback;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override private function internalRequest(url:String):Void {
|
override private function internalRequest(url:String):Void {
|
||||||
loader = buildLoader();
|
loader = buildLoader();
|
||||||
loader.load(new URLRequest(url), buildLoaderContext());
|
loader.load(new URLRequest(url), buildLoaderContext());
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package haxework.net;
|
package haxework.net;
|
||||||
|
|
||||||
|
import flash.utils.ByteArray;
|
||||||
import flash.display.LoaderInfo;
|
import flash.display.LoaderInfo;
|
||||||
import flash.display.Loader;
|
import flash.display.Loader;
|
||||||
import flash.display.Bitmap;
|
import flash.display.Bitmap;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package haxework.net.order;
|
package haxework.net.order;
|
||||||
|
|
||||||
import Lambda;
|
import haxework.storage.IStorage;
|
||||||
|
import haxework.provider.Provider;
|
||||||
import haxework.net.callback.Callback;
|
import haxework.net.callback.Callback;
|
||||||
import Type.ValueType;
|
|
||||||
import com.abit.umix.prepare.AutoCallback;
|
import com.abit.umix.prepare.AutoCallback;
|
||||||
import flash.display.BitmapData;
|
import flash.display.BitmapData;
|
||||||
import haxework.net.callback.ICallback;
|
import haxework.net.callback.ICallback;
|
||||||
|
|||||||
@@ -5,5 +5,5 @@ import flash.utils.ByteArray;
|
|||||||
interface IStorage {
|
interface IStorage {
|
||||||
public function exists(key:String):Bool;
|
public function exists(key:String):Bool;
|
||||||
public function write(key:String, value:ByteArray):Void;
|
public function write(key:String, value:ByteArray):Void;
|
||||||
public function read(ley:String):Null<ByteArray>;
|
public function read(key:String):Null<ByteArray>;
|
||||||
}
|
}
|
||||||
@@ -1,23 +1,24 @@
|
|||||||
package haxework.storage;
|
package haxework.storage;
|
||||||
|
|
||||||
|
import haxe.crypto.Md5;
|
||||||
import flash.net.SharedObject;
|
import flash.net.SharedObject;
|
||||||
import flash.utils.ByteArray;
|
import flash.utils.ByteArray;
|
||||||
|
|
||||||
class SharedObjectStorage implements IStorage {
|
class SharedObjectStorage implements IStorage {
|
||||||
|
|
||||||
public function exists(key:String):Bool {
|
public function exists(key:String):Bool {
|
||||||
var so:SharedObject = SharedObject.getLocal(key);
|
var so:SharedObject = SharedObject.getLocal("storage/" + Md5.encode(key));
|
||||||
return so.size > 0;
|
return so.size > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function write(key:String, value:ByteArray):Void {
|
public function write(key:String, value:ByteArray):Void {
|
||||||
var so:SharedObject = SharedObject.getLocal(key);
|
var so:SharedObject = SharedObject.getLocal("storage/" + Md5.encode(key));
|
||||||
so.setProperty("value", value);
|
so.setProperty("value", value);
|
||||||
so.flush();
|
so.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function read(key:String):Null<ByteArray> {
|
public function read(key:String):Null<ByteArray> {
|
||||||
var so:SharedObject = SharedObject.getLocal(key);
|
var so:SharedObject = SharedObject.getLocal("storage/" + Md5.encode(key));
|
||||||
return so.data.value;
|
return so.data.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user