示例#1
0
    def create_directory(self, name):
        name = STORAGE.get_valid_name(name)
        tmpfile = os.path.join(name, '.tmp')

        path = os.path.join(self.path, tmpfile)
        STORAGE.save(path, ContentFile(''))
        if not app.models.Files.objects.filter(location=os.path.join(self.path, name)).exists():
            app.models.Files.objects.create(location=os.path.join(self.path, name),
                                            link='sharewood.cloud/public/{}'.format(hashlib.sha256(os.path.join(self.path, name).encode('utf-8')).hexdigest()),
                                            blocked=1,
                                            url_access=0)
        STORAGE.delete(path)
示例#2
0
 def _helper(name, filetype):
     return {
         'filepath': os.path.join(self.path, name),
         'filetype': filetype,
         'filename': name,
         'filedate': STORAGE.get_modified_time(os.path.join(self.path, name)),
         'filesize': sizeof_fmt(STORAGE.size(os.path.join(self.path, name))),
         'fileurl' : os.path.join(settings.MEDIA_URL, self.abspath, name),
         'link': app.models.Files.objects.get(location=os.path.join(self.path, name)).link,
         'blocked': app.models.Files.objects.get(location=os.path.join(self.path, name)).blocked,
         'url_access': app.models.Files.objects.get(location=os.path.join(self.path, name)).url_access,
         'allowed_urls': app.models.Files.objects.get(location=os.path.join(self.path, name)).allowed_urls,
     }
示例#3
0
 def _helper(name, filetype):
     return {
         'filepath': os.path.join(location, name),
         'filetype': filetype,
         'filename': name,
         'filedate': STORAGE.get_modified_time(os.path.join(location, name)),
         'filesize': sizeof_fmt(STORAGE.size(os.path.join(location, name))),
         'fileurl': os.path.join(app.settings.MEDIA_URL, location, name),
         'link': link,
         'blocked': app.models.Files.objects.get(link='sharewood.cloud/public/{}'.format(link)).blocked,
         'url_access': app.models.Files.objects.get(link='sharewood.cloud/public/{}'.format(link)).url_access,
         'allowed_urls': app.models.Files.objects.get(link='sharewood.cloud/public/{}'.format(link)).allowed_urls,
     }
示例#4
0
 def file_details(self):
     filename = self.path.rsplit('/', 1)[-1]
     return {
         'directory': os.path.dirname(self.path),
         'filepath': self.path,
         'filename': filename,
         'filesize': sizeof_fmt(STORAGE.size(self.location)),
         'filedate': STORAGE.get_modified_time(self.location),
         'fileurl': self.url,
         'link':  app.models.Files.objects.get(location=os.path.join(self.path, filename)).link,
         'blocked': app.models.Files.objects.get(location=os.path.join(self.path, filename)).blocked,
         'url_access': app.models.Files.objects.get(location=os.path.join(self.path, filename)).url_access,
         'allowed_urls': app.models.Files.objects.get(location=os.path.join(self.path, filename)).allowed_urls,
     }
示例#5
0
    def upload_file(self, rel_path, filedata):
        filename = STORAGE.get_valid_name(filedata.name)
        filepath = os.path.join(self.path, rel_path)

        app.signals.filemanager_pre_upload.send(sender=self.__class__, filename=filename, path=self.path, filepath=filepath)
        if app.models.Files.objects.filter(location=filepath).exists():
            self.remove(filepath)

        STORAGE.save(filepath, filedata)
        app.models.Files.objects.create(location=filepath,
                                        link='sharewood.cloud/public/{}'.format(hashlib.sha256(filepath.encode('utf-8')).hexdigest()),
                                        blocked=1,
                                        url_access=0)
        app.signals.filemanager_post_upload.send(sender=self.__class__, filename=filename, path=self.path, filepath=filepath)
        return filename
示例#6
0
    def directory_list(self):
        listing = []

        directories, files = STORAGE.listdir(self.location)

        def _helper(name, filetype):
            return {
                'filepath': os.path.join(self.path, name),
                'filetype': filetype,
                'filename': name,
                'filedate': STORAGE.get_modified_time(os.path.join(self.path, name)),
                'filesize': sizeof_fmt(STORAGE.size(os.path.join(self.path, name))),
                'fileurl' : os.path.join(settings.MEDIA_URL, self.abspath, name),
                'link': app.models.Files.objects.get(location=os.path.join(self.path, name)).link,
                'blocked': app.models.Files.objects.get(location=os.path.join(self.path, name)).blocked,
                'url_access': app.models.Files.objects.get(location=os.path.join(self.path, name)).url_access,
                'allowed_urls': app.models.Files.objects.get(location=os.path.join(self.path, name)).allowed_urls,
            }

        for directoryname in directories:
            listing.append(_helper(directoryname, 'Directory'))

        for filename in files:
            listing.append(_helper(filename, 'File'))

        return listing
示例#7
0
    def public_directory_list(self, location, link):

        def _helper(name, filetype):
            return {
                'filepath': os.path.join(location, name),
                'filetype': filetype,
                'filename': name,
                'filedate': STORAGE.get_modified_time(os.path.join(location, name)),
                'filesize': sizeof_fmt(STORAGE.size(os.path.join(location, name))),
                'fileurl': os.path.join(app.settings.MEDIA_URL, location, name),
                'link': link,
                'blocked': app.models.Files.objects.get(link='sharewood.cloud/public/{}'.format(link)).blocked,
                'url_access': app.models.Files.objects.get(link='sharewood.cloud/public/{}'.format(link)).url_access,
                'allowed_urls': app.models.Files.objects.get(link='sharewood.cloud/public/{}'.format(link)).allowed_urls,
            }

        listing = []

        if os.path.isfile(os.path.join(app.settings.MEDIA_ROOT, location)):

            location, filename = location.split('/')[:-1], location.split('/')[-1]
            if location:
                location = os.path.join(*location)
            else:
                location = ''
            listing.append(_helper(filename, 'File'))
            return listing

        directories, files = STORAGE.listdir(location)

        for directoryname in directories:
            listing.append(_helper(directoryname, 'Directory'))

        for filename in files:
            listing.append(_helper(filename, 'File'))

        return listing