Compare commits
1 Commits
9462a74437
...
1d2f25ef04
| Author | SHA1 | Date | |
|---|---|---|---|
| 1d2f25ef04 |
@@ -53,6 +53,30 @@ class ObjID {
|
||||
return new ObjID(this.bucket,parts.join("/"))
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the parent of the object. If Obj is a file then the containing directory
|
||||
* if Obj is a directory it returns the parent
|
||||
* @returns parent ObjID or null if already at root
|
||||
*/
|
||||
public parent(): ObjID | null {
|
||||
if (this.key == "/") {
|
||||
// Already at root. We dont have a parent
|
||||
return null
|
||||
}
|
||||
|
||||
if (this.isDirectory()) {
|
||||
const parts = this.key.split("/")
|
||||
const parent = new ObjID(this.bucket, parts.slice(0,-2).join("/") + "/")
|
||||
parent.normalize()
|
||||
return parent
|
||||
} else {
|
||||
const parts = this.key.split("/")
|
||||
const parent = new ObjID(this.bucket, parts.slice(0,-1).join("/") + "/")
|
||||
parent.normalize()
|
||||
return parent
|
||||
}
|
||||
}
|
||||
|
||||
public static fromString(from: string): ObjID{
|
||||
const match = stringRegex.exec(from)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user