-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5422148
commit 3f11227
Showing
9 changed files
with
178 additions
and
92 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import { MethodCallArgs } from '../WebDAVRequest'; | ||
export default function (arg: MethodCallArgs, callback: any): void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var WebDAVRequest_1 = require("../WebDAVRequest"); | ||
var Resource_1 = require("../../resource/Resource"); | ||
var path = require("path"); | ||
function createResource(arg, callback, validCallback) { | ||
arg.server.getResourceFromPath(arg.path.getParent(), function (e, r) { | ||
if (e) { | ||
arg.setCode(WebDAVRequest_1.HTTPCodes.MethodNotAllowed); | ||
callback(); | ||
return; | ||
} | ||
if (!r.fsManager) { | ||
arg.setCode(WebDAVRequest_1.HTTPCodes.InternalServerError); | ||
callback(); | ||
return; | ||
} | ||
var resource = r.fsManager.newResource(arg.uri, path.basename(arg.uri), Resource_1.ResourceType.File, r); | ||
resource.create(function (e) { | ||
if (e) { | ||
arg.setCode(WebDAVRequest_1.HTTPCodes.InternalServerError); | ||
callback(); | ||
return; | ||
} | ||
r.addChild(resource, function (e) { | ||
if (e) { | ||
arg.setCode(WebDAVRequest_1.HTTPCodes.InternalServerError); | ||
callback(); | ||
} | ||
else | ||
validCallback(resource); | ||
}); | ||
}); | ||
}); | ||
} | ||
function default_1(arg, callback) { | ||
arg.getResource(function (e, r) { | ||
if (arg.contentLength === 0) { | ||
if (r) { | ||
r.write(new Buffer(0), function (e) { | ||
if (e) | ||
arg.setCode(WebDAVRequest_1.HTTPCodes.InternalServerError); | ||
else | ||
arg.setCode(WebDAVRequest_1.HTTPCodes.OK); | ||
callback(); | ||
}); | ||
return; | ||
} | ||
createResource(arg, callback, function (r) { | ||
arg.setCode(WebDAVRequest_1.HTTPCodes.OK); | ||
callback(); | ||
}); | ||
} | ||
else { | ||
var data = new Buffer(arg.data); | ||
if (e) { | ||
createResource(arg, callback, function (r) { | ||
r.write(data, function (e) { | ||
if (e) | ||
arg.setCode(WebDAVRequest_1.HTTPCodes.InternalServerError); | ||
else | ||
arg.setCode(WebDAVRequest_1.HTTPCodes.OK); | ||
callback(); | ||
}); | ||
}); | ||
return; | ||
} | ||
r.write(data, function (e) { | ||
if (e) | ||
arg.setCode(WebDAVRequest_1.HTTPCodes.InternalServerError); | ||
else | ||
arg.setCode(WebDAVRequest_1.HTTPCodes.OK); | ||
callback(); | ||
}); | ||
} | ||
}); | ||
} | ||
exports.default = default_1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import NotImplemented from './NotImplemented' | ||
import Propfind from './Propfind' | ||
import Mkcol from './Mkcol' | ||
import Put from './Put' | ||
import Get from './Get' | ||
|
||
export default { | ||
NotImplemented, | ||
Propfind, | ||
Mkcol, | ||
Put, | ||
Get | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { HTTPCodes, MethodCallArgs, WebDAVRequest } from '../WebDAVRequest' | ||
import { IResource, ResourceType } from '../../resource/Resource' | ||
import * as path from 'path' | ||
|
||
function createResource(arg : MethodCallArgs, callback, validCallback : (resource : IResource) => void) | ||
{ | ||
arg.server.getResourceFromPath(arg.path.getParent(), (e, r) => { | ||
if(e) | ||
{ | ||
arg.setCode(HTTPCodes.MethodNotAllowed) | ||
callback() | ||
return; | ||
} | ||
|
||
if(!r.fsManager) | ||
{ | ||
arg.setCode(HTTPCodes.InternalServerError) | ||
callback(); | ||
return; | ||
} | ||
|
||
const resource = r.fsManager.newResource(arg.uri, path.basename(arg.uri), ResourceType.File, r); | ||
resource.create((e) => { | ||
if(e) | ||
{ | ||
arg.setCode(HTTPCodes.InternalServerError) | ||
callback(); | ||
return; | ||
} | ||
|
||
r.addChild(resource, (e) => { | ||
if(e) | ||
{ | ||
arg.setCode(HTTPCodes.InternalServerError) | ||
callback(); | ||
} | ||
else | ||
validCallback(resource); | ||
}) | ||
}) | ||
}) | ||
} | ||
|
||
export default function(arg : MethodCallArgs, callback) | ||
{ | ||
|
||
arg.getResource((e, r) => { | ||
if(arg.contentLength === 0) | ||
{ // Create file | ||
if(r) | ||
{ // Resource exists => empty it | ||
r.write(new Buffer(0), (e) => { | ||
if(e) | ||
arg.setCode(HTTPCodes.InternalServerError) | ||
else | ||
arg.setCode(HTTPCodes.OK) | ||
callback() | ||
}) | ||
return; | ||
} | ||
|
||
createResource(arg, callback, (r) => { | ||
arg.setCode(HTTPCodes.OK) | ||
callback(); | ||
}) | ||
} | ||
else | ||
{ // Write to a file | ||
var data = new Buffer(arg.data); | ||
|
||
if(e) | ||
{ // Resource not found | ||
createResource(arg, callback, (r) => { | ||
r.write(data, (e) => { | ||
if(e) | ||
arg.setCode(HTTPCodes.InternalServerError) | ||
else | ||
arg.setCode(HTTPCodes.OK) | ||
callback(); | ||
}) | ||
}) | ||
return; | ||
} | ||
|
||
r.write(data, (e) => { | ||
if(e) | ||
arg.setCode(HTTPCodes.InternalServerError) | ||
else | ||
arg.setCode(HTTPCodes.OK) | ||
callback(); | ||
}) | ||
} | ||
}) | ||
} |