Procházet zdrojové kódy

VLCHTTPConnection: Split 300++ LoC response method

Felix Paul Kühne před 9 roky
rodič
revize
85e12fd217
2 změnil soubory, kde provedl 303 přidání a 254 odebrání
  1. 289 249
      Sources/VLCHTTPConnection.m
  2. 14 5
      VLC for iOS.xcodeproj/project.pbxproj

+ 289 - 249
Sources/VLCHTTPConnection.m

@@ -97,312 +97,352 @@
     return [super expectsRequestBodyFromMethod:method atPath:path];
 }
 
-- (NSObject<HTTPResponse> *)httpResponseForMethod:(NSString *)method URI:(NSString *)path
+- (NSObject<HTTPResponse> *)_httpPOSTresponseUploadJSON
 {
-    if ([method isEqualToString:@"POST"] && [path isEqualToString:@"/upload.json"])
-        return [[HTTPDataResponse alloc] initWithData:[@"\"OK\"" dataUsingEncoding:NSUTF8StringEncoding]];
+    return [[HTTPDataResponse alloc] initWithData:[@"\"OK\"" dataUsingEncoding:NSUTF8StringEncoding]];
+}
 
 #if TARGET_OS_IOS
-    if ([path hasPrefix:@"/download/"]) {
-        NSString *filePath = [[path stringByReplacingOccurrencesOfString:@"/download/" withString:@""]stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-        HTTPFileResponse *fileResponse = [[HTTPFileResponse alloc] initWithFilePath:filePath forConnection:self];
-        fileResponse.contentType = @"application/octet-stream";
-        return fileResponse;
-    }
-    if ([path hasPrefix:@"/thumbnail"]) {
-        NSString *filePath = [[path stringByReplacingOccurrencesOfString:@"/thumbnail/" withString:@""]stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-        filePath = [filePath stringByReplacingOccurrencesOfString:@".png" withString:@""];
-
-        NSManagedObjectContext *moc = [[MLMediaLibrary sharedMediaLibrary] managedObjectContext];
-        if (moc) {
-            NSPersistentStoreCoordinator *psc = [moc persistentStoreCoordinator];
-            if (psc) {
-                NSManagedObject *mo = nil;
-                @try {
-                    mo = [moc existingObjectWithID:[psc managedObjectIDForURIRepresentation:[NSURL URLWithString:filePath]] error:nil];
-                }@catch (NSException *exeption) {
-                    // somebody gave us a malformed or stale URIRepresentation
-                }
+- (NSObject<HTTPResponse> *)_httpGETDownloadForPath:(NSString *)path
+{
+    NSString *filePath = [[path stringByReplacingOccurrencesOfString:@"/download/" withString:@""]stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+    HTTPFileResponse *fileResponse = [[HTTPFileResponse alloc] initWithFilePath:filePath forConnection:self];
+    fileResponse.contentType = @"application/octet-stream";
+    return fileResponse;
+}
 
-                NSData *theData;
-                NSString *contentType;
-
-                /* devices category 3 and faster include HW accelerated JPEG encoding
-                 * so we can make our transfers faster by using waaay smaller images */
-                if ([[UIDevice currentDevice] speedCategory] < 3) {
-                    theData = UIImagePNGRepresentation([VLCThumbnailsCache thumbnailForManagedObject:mo]);
-                    contentType = @"image/png";
-                } else {
-                    theData = UIImageJPEGRepresentation([VLCThumbnailsCache thumbnailForManagedObject:mo], .9);
-                    contentType = @"image/jpg";
-                }
+- (NSObject<HTTPResponse> *)_httpGETThumbnailForPath:(NSString *)path
+{
+    NSString *filePath = [[path stringByReplacingOccurrencesOfString:@"/thumbnail/" withString:@""]stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+    filePath = [filePath stringByReplacingOccurrencesOfString:@".png" withString:@""];
+
+    NSManagedObjectContext *moc = [[MLMediaLibrary sharedMediaLibrary] managedObjectContext];
+    if (moc) {
+        NSPersistentStoreCoordinator *psc = [moc persistentStoreCoordinator];
+        if (psc) {
+            NSManagedObject *mo = nil;
+            @try {
+                mo = [moc existingObjectWithID:[psc managedObjectIDForURIRepresentation:[NSURL URLWithString:filePath]] error:nil];
+            }@catch (NSException *exeption) {
+                // somebody gave us a malformed or stale URIRepresentation
+            }
 
-                if (theData) {
-                    HTTPDataResponse *dataResponse = [[HTTPDataResponse alloc] initWithData:theData];
-                    dataResponse.contentType = contentType;
-                    return dataResponse;
-                }
+            NSData *theData;
+            NSString *contentType;
+
+            /* devices category 3 and faster include HW accelerated JPEG encoding
+             * so we can make our transfers faster by using waaay smaller images */
+            if ([[UIDevice currentDevice] speedCategory] < 3) {
+                theData = UIImagePNGRepresentation([VLCThumbnailsCache thumbnailForManagedObject:mo]);
+                contentType = @"image/png";
+            } else {
+                theData = UIImageJPEGRepresentation([VLCThumbnailsCache thumbnailForManagedObject:mo], .9);
+                contentType = @"image/jpg";
+            }
+
+            if (theData) {
+                HTTPDataResponse *dataResponse = [[HTTPDataResponse alloc] initWithData:theData];
+                dataResponse.contentType = contentType;
+                return dataResponse;
             }
         }
     }
+}
+
+- (NSObject<HTTPResponse> *)_httpGETLibraryForPath:(NSString *)path
+{
     NSString *filePath = [self filePathForURI:path];
     NSString *documentRoot = [config documentRoot];
     NSString *relativePath = [filePath substringFromIndex:[documentRoot length]];
     BOOL shouldReturnLibVLCXML = [relativePath isEqualToString:@"/libMediaVLC.xml"];
 
-    if ([relativePath isEqualToString:@"/index.html"] || shouldReturnLibVLCXML) {
-        NSMutableArray *allMedia = [[NSMutableArray alloc] init];
+    NSMutableArray *allMedia = [[NSMutableArray alloc] init];
 
-        /* add all albums */
-        NSArray *allAlbums = [MLAlbum allAlbums];
-        for (MLAlbum *album in allAlbums) {
-            if (album.name.length > 0 && album.tracks.count > 1)
-                [allMedia addObject:album];
-        }
+    /* add all albums */
+    NSArray *allAlbums = [MLAlbum allAlbums];
+    for (MLAlbum *album in allAlbums) {
+        if (album.name.length > 0 && album.tracks.count > 1)
+            [allMedia addObject:album];
+    }
 
-        /* add all shows */
-        NSArray *allShows = [MLShow allShows];
-        for (MLShow *show in allShows) {
-            if (show.name.length > 0 && show.episodes.count > 1)
-                [allMedia addObject:show];
-        }
+    /* add all shows */
+    NSArray *allShows = [MLShow allShows];
+    for (MLShow *show in allShows) {
+        if (show.name.length > 0 && show.episodes.count > 1)
+            [allMedia addObject:show];
+    }
 
-        /* add all folders*/
-        NSArray *allFolders = [MLLabel allLabels];
-        for (MLLabel *folder in allFolders)
-            [allMedia addObject:folder];
+    /* add all folders*/
+    NSArray *allFolders = [MLLabel allLabels];
+    for (MLLabel *folder in allFolders)
+        [allMedia addObject:folder];
 
-        /* add all remaining files */
-        NSArray *allFiles = [MLFile allFiles];
-        for (MLFile *file in allFiles) {
-            if (file.labels.count > 0) continue;
+    /* add all remaining files */
+    NSArray *allFiles = [MLFile allFiles];
+    for (MLFile *file in allFiles) {
+        if (file.labels.count > 0) continue;
 
-            if (!file.isShowEpisode && !file.isAlbumTrack)
+        if (!file.isShowEpisode && !file.isAlbumTrack)
+            [allMedia addObject:file];
+        else if (file.isShowEpisode) {
+            if (file.showEpisode.show.episodes.count < 2)
+                [allMedia addObject:file];
+        } else if (file.isAlbumTrack) {
+            if (file.albumTrack.album.tracks.count < 2)
                 [allMedia addObject:file];
-            else if (file.isShowEpisode) {
-                if (file.showEpisode.show.episodes.count < 2)
-                    [allMedia addObject:file];
-            } else if (file.isAlbumTrack) {
-                if (file.albumTrack.album.tracks.count < 2)
-                    [allMedia addObject:file];
-            }
         }
+    }
 
-        NSUInteger mediaCount = allMedia.count;
-        NSMutableArray *mediaInHtml = [[NSMutableArray alloc] initWithCapacity:mediaCount];
-        NSMutableArray *mediaInXml = [[NSMutableArray alloc] initWithCapacity:mediaCount];
-        NSString *hostName = [[VLCHTTPUploaderController sharedInstance] hostname];
-        NSString *duration;
-
-        for (NSManagedObject *mo in allMedia) {
-            if ([mo isKindOfClass:[MLFile class]]) {
-                MLFile *file = (MLFile *)mo;
-                duration = [[VLCTime timeWithNumber:file.duration] stringValue];
+    NSUInteger mediaCount = allMedia.count;
+    NSMutableArray *mediaInHtml = [[NSMutableArray alloc] initWithCapacity:mediaCount];
+    NSMutableArray *mediaInXml = [[NSMutableArray alloc] initWithCapacity:mediaCount];
+    NSString *hostName = [[VLCHTTPUploaderController sharedInstance] hostname];
+    NSString *duration;
+
+    for (NSManagedObject *mo in allMedia) {
+        if ([mo isKindOfClass:[MLFile class]]) {
+            MLFile *file = (MLFile *)mo;
+            duration = [[VLCTime timeWithNumber:file.duration] stringValue];
+            [mediaInHtml addObject:[NSString stringWithFormat:
+                                    @"<div style=\"background-image:url('thumbnail/%@.png')\"> \
+                                    <a href=\"download/%@\" class=\"inner\"> \
+                                    <div class=\"down icon\"></div> \
+                                    <div class=\"infos\"> \
+                                    <span class=\"first-line\">%@</span> \
+                                    <span class=\"second-line\">%@ - %0.2f MB</span> \
+                                    </div> \
+                                    </a> \
+                                    </div>",
+                                    file.objectID.URIRepresentation,
+                                    [file.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
+                                    file.title,
+                                    duration, (float)(file.fileSizeInBytes / 1e6)]];
+            if (shouldReturnLibVLCXML) {
+                NSString *pathSub = [self _checkIfSubtitleWasFound:file.path];
+                if (pathSub)
+                    pathSub = [NSString stringWithFormat:@"http://%@/download/%@", hostName, pathSub];
+                [mediaInXml addObject:[NSString stringWithFormat:@"<Media title=\"%@\" thumb=\"http://%@/thumbnail/%@.png\" duration=\"%@\" size=\"%li\" pathfile=\"http://%@/download/%@\" pathSubtitle=\"%@\"/>", file.title, hostName, file.objectID.URIRepresentation.absoluteString, duration, file.fileSizeInBytes, hostName, [file.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], pathSub]];
+            }
+        }
+        else if ([mo isKindOfClass:[MLShow class]]) {
+            MLShow *show = (MLShow *)mo;
+            NSArray *episodes = [show sortedEpisodes];
+            [mediaInHtml addObject:[NSString stringWithFormat:
+                                    @"<div style=\"background-image:url('thumbnail/%@.png')\"> \
+                                    <a href=\"#\" class=\"inner folder\"> \
+                                    <div class=\"open icon\"></div> \
+                                    <div class=\"infos\"> \
+                                    <span class=\"first-line\">%@</span> \
+                                    <span class=\"second-line\">%lu items</span> \
+                                    </div> \
+                                    </a> \
+                                    <div class=\"content\">",
+                                    mo.objectID.URIRepresentation,
+                                    show.name,
+                                    (unsigned long)[episodes count]]];
+            for (MLShowEpisode *showEp in episodes) {
+                MLFile *anyFileFromEpisode = (MLFile *)[[showEp files] anyObject];
+                duration = [[VLCTime timeWithNumber:[anyFileFromEpisode duration]] stringValue];
                 [mediaInHtml addObject:[NSString stringWithFormat:
                                         @"<div style=\"background-image:url('thumbnail/%@.png')\"> \
                                         <a href=\"download/%@\" class=\"inner\"> \
                                         <div class=\"down icon\"></div> \
                                         <div class=\"infos\"> \
-                                        <span class=\"first-line\">%@</span> \
+                                        <span class=\"first-line\">S%@E%@ - %@</span> \
                                         <span class=\"second-line\">%@ - %0.2f MB</span> \
                                         </div> \
                                         </a> \
                                         </div>",
-                                        file.objectID.URIRepresentation,
-                                        [file.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
-                                        file.title,
-                                        duration, (float)(file.fileSizeInBytes / 1e6)]];
+                                        showEp.objectID.URIRepresentation,
+                                        [anyFileFromEpisode.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
+                                        showEp.seasonNumber,
+                                        showEp.episodeNumber,
+                                        showEp.name,
+                                        duration, (float)([anyFileFromEpisode fileSizeInBytes] / 1e6)]];
                 if (shouldReturnLibVLCXML) {
-                    NSString *pathSub = [self _checkIfSubtitleWasFound:file.path];
-                    if (pathSub)
+                    NSString *pathSub = [self _checkIfSubtitleWasFound:[anyFileFromEpisode path]];
+                    if (![pathSub isEqualToString:@""])
                         pathSub = [NSString stringWithFormat:@"http://%@/download/%@", hostName, pathSub];
-                    [mediaInXml addObject:[NSString stringWithFormat:@"<Media title=\"%@\" thumb=\"http://%@/thumbnail/%@.png\" duration=\"%@\" size=\"%li\" pathfile=\"http://%@/download/%@\" pathSubtitle=\"%@\"/>", file.title, hostName, file.objectID.URIRepresentation.absoluteString, duration, file.fileSizeInBytes, hostName, [file.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], pathSub]];
+                    [mediaInXml addObject:[NSString stringWithFormat:@"<Media title=\"%@ - S%@E%@\" thumb=\"http://%@/thumbnail/%@.png\" duration=\"%@\" size=\"%li\" pathfile=\"http://%@/download/%@\" pathSubtitle=\"%@\"/>", show.name, showEp.seasonNumber, showEp.episodeNumber, hostName, showEp.objectID.URIRepresentation, duration, [anyFileFromEpisode fileSizeInBytes], hostName, [anyFileFromEpisode.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], pathSub]];
                 }
             }
-            else if ([mo isKindOfClass:[MLShow class]]) {
-                MLShow *show = (MLShow *)mo;
-                NSArray *episodes = [show sortedEpisodes];
+            [mediaInHtml addObject:@"</div></div>"];
+        } else if ([mo isKindOfClass:[MLLabel class]]) {
+            MLLabel *label = (MLLabel *)mo;
+            NSArray *folderItems = [label sortedFolderItems];
+            [mediaInHtml addObject:[NSString stringWithFormat:
+                                    @"<div style=\"background-image:url('thumbnail/%@.png')\"> \
+                                    <a href=\"#\" class=\"inner folder\"> \
+                                    <div class=\"open icon\"></div> \
+                                    <div class=\"infos\"> \
+                                    <span class=\"first-line\">%@</span> \
+                                    <span class=\"second-line\">%lu items</span> \
+                                    </div> \
+                                    </a> \
+                                    <div class=\"content\">",
+                                    label.objectID.URIRepresentation,
+                                    label.name,
+                                    (unsigned long)folderItems.count]];
+            for (MLFile *file in folderItems) {
+                duration = [[VLCTime timeWithNumber:[file duration]] stringValue];
                 [mediaInHtml addObject:[NSString stringWithFormat:
                                         @"<div style=\"background-image:url('thumbnail/%@.png')\"> \
-                                        <a href=\"#\" class=\"inner folder\"> \
-                                        <div class=\"open icon\"></div> \
-                                        <div class=\"infos\"> \
-                                        <span class=\"first-line\">%@</span> \
-                                        <span class=\"second-line\">%lu items</span> \
-                                        </div> \
-                                        </a> \
-                                        <div class=\"content\">",
-                                        mo.objectID.URIRepresentation,
-                                        show.name,
-                                        (unsigned long)[episodes count]]];
-                for (MLShowEpisode *showEp in episodes) {
-                    MLFile *anyFileFromEpisode = (MLFile *)[[showEp files] anyObject];
-                    duration = [[VLCTime timeWithNumber:[anyFileFromEpisode duration]] stringValue];
-                    [mediaInHtml addObject:[NSString stringWithFormat:
-                                            @"<div style=\"background-image:url('thumbnail/%@.png')\"> \
-                                            <a href=\"download/%@\" class=\"inner\"> \
-                                            <div class=\"down icon\"></div> \
-                                            <div class=\"infos\"> \
-                                            <span class=\"first-line\">S%@E%@ - %@</span> \
-                                            <span class=\"second-line\">%@ - %0.2f MB</span> \
-                                            </div> \
-                                            </a> \
-                                            </div>",
-                                            showEp.objectID.URIRepresentation,
-                                            [anyFileFromEpisode.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
-                                            showEp.seasonNumber,
-                                            showEp.episodeNumber,
-                                            showEp.name,
-                                            duration, (float)([anyFileFromEpisode fileSizeInBytes] / 1e6)]];
-                    if (shouldReturnLibVLCXML) {
-                        NSString *pathSub = [self _checkIfSubtitleWasFound:[anyFileFromEpisode path]];
-                        if (![pathSub isEqualToString:@""])
-                            pathSub = [NSString stringWithFormat:@"http://%@/download/%@", hostName, pathSub];
-                        [mediaInXml addObject:[NSString stringWithFormat:@"<Media title=\"%@ - S%@E%@\" thumb=\"http://%@/thumbnail/%@.png\" duration=\"%@\" size=\"%li\" pathfile=\"http://%@/download/%@\" pathSubtitle=\"%@\"/>", show.name, showEp.seasonNumber, showEp.episodeNumber, hostName, showEp.objectID.URIRepresentation, duration, [anyFileFromEpisode fileSizeInBytes], hostName, [anyFileFromEpisode.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], pathSub]];
-                    }
-                }
-                [mediaInHtml addObject:@"</div></div>"];
-            } else if ([mo isKindOfClass:[MLLabel class]]) {
-                MLLabel *label = (MLLabel *)mo;
-                NSArray *folderItems = [label sortedFolderItems];
-                [mediaInHtml addObject:[NSString stringWithFormat:
-                                        @"<div style=\"background-image:url('thumbnail/%@.png')\"> \
-                                        <a href=\"#\" class=\"inner folder\"> \
-                                        <div class=\"open icon\"></div> \
+                                        <a href=\"download/%@\" class=\"inner\"> \
+                                        <div class=\"down icon\"></div> \
                                         <div class=\"infos\"> \
                                         <span class=\"first-line\">%@</span> \
-                                        <span class=\"second-line\">%lu items</span> \
+                                        <span class=\"second-line\">%@ - %0.2f MB</span> \
                                         </div> \
                                         </a> \
-                                        <div class=\"content\">",
-                                        label.objectID.URIRepresentation,
-                                        label.name,
-                                        (unsigned long)folderItems.count]];
-                for (MLFile *file in folderItems) {
-                    duration = [[VLCTime timeWithNumber:[file duration]] stringValue];
-                    [mediaInHtml addObject:[NSString stringWithFormat:
-                                            @"<div style=\"background-image:url('thumbnail/%@.png')\"> \
-                                            <a href=\"download/%@\" class=\"inner\"> \
-                                            <div class=\"down icon\"></div> \
-                                            <div class=\"infos\"> \
-                                            <span class=\"first-line\">%@</span> \
-                                            <span class=\"second-line\">%@ - %0.2f MB</span> \
-                                            </div> \
-                                            </a> \
-                                            </div>",
-                                            file.objectID.URIRepresentation,
-                                            [file.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
-                                            file.title,
-                                            duration, (float)(file.fileSizeInBytes / 1e6)]];
-                    if (shouldReturnLibVLCXML) {
-                        NSString *pathSub = [self _checkIfSubtitleWasFound:file.path];
-                        if (pathSub)
-                            pathSub = [NSString stringWithFormat:@"http://%@/download/%@", hostName, pathSub];
-                        [mediaInXml addObject:[NSString stringWithFormat:@"<Media title=\"%@\" thumb=\"http://%@/thumbnail/%@.png\" duration=\"%@\" size=\"%li\" pathfile=\"http://%@/download/%@\" pathSubtitle=\"%@\"/>", file.title, hostName, file.objectID.URIRepresentation, duration, file.fileSizeInBytes, hostName, [file.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], pathSub]];
-                    }
+                                        </div>",
+                                        file.objectID.URIRepresentation,
+                                        [file.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
+                                        file.title,
+                                        duration, (float)(file.fileSizeInBytes / 1e6)]];
+                if (shouldReturnLibVLCXML) {
+                    NSString *pathSub = [self _checkIfSubtitleWasFound:file.path];
+                    if (pathSub)
+                        pathSub = [NSString stringWithFormat:@"http://%@/download/%@", hostName, pathSub];
+                    [mediaInXml addObject:[NSString stringWithFormat:@"<Media title=\"%@\" thumb=\"http://%@/thumbnail/%@.png\" duration=\"%@\" size=\"%li\" pathfile=\"http://%@/download/%@\" pathSubtitle=\"%@\"/>", file.title, hostName, file.objectID.URIRepresentation, duration, file.fileSizeInBytes, hostName, [file.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], pathSub]];
                 }
-                [mediaInHtml addObject:@"</div></div>"];
-            } else if ([mo isKindOfClass:[MLAlbum class]]) {
-                MLAlbum *album = (MLAlbum *)mo;
-                NSArray *albumTracks = [album sortedTracks];
+            }
+            [mediaInHtml addObject:@"</div></div>"];
+        } else if ([mo isKindOfClass:[MLAlbum class]]) {
+            MLAlbum *album = (MLAlbum *)mo;
+            NSArray *albumTracks = [album sortedTracks];
+            [mediaInHtml addObject:[NSString stringWithFormat:
+                                    @"<div style=\"background-image:url('thumbnail/%@.png')\"> \
+                                    <a href=\"#\" class=\"inner folder\"> \
+                                    <div class=\"open icon\"></div> \
+                                    <div class=\"infos\"> \
+                                    <span class=\"first-line\">%@</span> \
+                                    <span class=\"second-line\">%lu items</span> \
+                                    </div> \
+                                    </a> \
+                                    <div class=\"content\">",
+                                    album.objectID.URIRepresentation,
+                                    album.name,
+                                    (unsigned long)albumTracks.count]];
+            for (MLAlbumTrack *track in albumTracks) {
+                MLFile *anyFileFromTrack = [track anyFileFromTrack];
+                duration = [[VLCTime timeWithNumber:[anyFileFromTrack duration]] stringValue];
                 [mediaInHtml addObject:[NSString stringWithFormat:
                                         @"<div style=\"background-image:url('thumbnail/%@.png')\"> \
-                                        <a href=\"#\" class=\"inner folder\"> \
-                                        <div class=\"open icon\"></div> \
+                                        <a href=\"download/%@\" class=\"inner\"> \
+                                        <div class=\"down icon\"></div> \
                                         <div class=\"infos\"> \
                                         <span class=\"first-line\">%@</span> \
-                                        <span class=\"second-line\">%lu items</span> \
+                                        <span class=\"second-line\">%@ - %0.2f MB</span> \
                                         </div> \
                                         </a> \
-                                        <div class=\"content\">",
-                                        album.objectID.URIRepresentation,
-                                        album.name,
-                                        (unsigned long)albumTracks.count]];
-                for (MLAlbumTrack *track in albumTracks) {
-                    MLFile *anyFileFromTrack = [track anyFileFromTrack];
-                    duration = [[VLCTime timeWithNumber:[anyFileFromTrack duration]] stringValue];
-                    [mediaInHtml addObject:[NSString stringWithFormat:
-                                            @"<div style=\"background-image:url('thumbnail/%@.png')\"> \
-                                            <a href=\"download/%@\" class=\"inner\"> \
-                                            <div class=\"down icon\"></div> \
-                                            <div class=\"infos\"> \
-                                            <span class=\"first-line\">%@</span> \
-                                            <span class=\"second-line\">%@ - %0.2f MB</span> \
-                                            </div> \
-                                            </a> \
-                                            </div>",
-                                            track.objectID.URIRepresentation,
-                                            [anyFileFromTrack.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
-                                            track.title,
-                                            duration, (float)([anyFileFromTrack fileSizeInBytes] / 1e6)]];
-                    if (shouldReturnLibVLCXML)
-                        [mediaInXml addObject:[NSString stringWithFormat:@"<Media title=\"%@\" thumb=\"http://%@/thumbnail/%@.png\" duration=\"%@\" size=\"%li\" pathfile=\"http://%@/download/%@\" pathSubtitle=\"\"/>", track.title, hostName, track.objectID.URIRepresentation, duration, [anyFileFromTrack fileSizeInBytes], hostName, [anyFileFromTrack.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
-                }
-                [mediaInHtml addObject:@"</div></div>"];
+                                        </div>",
+                                        track.objectID.URIRepresentation,
+                                        [anyFileFromTrack.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
+                                        track.title,
+                                        duration, (float)([anyFileFromTrack fileSizeInBytes] / 1e6)]];
+                if (shouldReturnLibVLCXML)
+                    [mediaInXml addObject:[NSString stringWithFormat:@"<Media title=\"%@\" thumb=\"http://%@/thumbnail/%@.png\" duration=\"%@\" size=\"%li\" pathfile=\"http://%@/download/%@\" pathSubtitle=\"\"/>", track.title, hostName, track.objectID.URIRepresentation, duration, [anyFileFromTrack fileSizeInBytes], hostName, [anyFileFromTrack.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
             }
+            [mediaInHtml addObject:@"</div></div>"];
         }
+    }
 
 
-        UIDevice *currentDevice = [UIDevice currentDevice];
-        NSString *deviceModel = [currentDevice model];
-        NSDictionary *replacementDict;
-        HTTPDynamicFileResponse *fileResponse;
-
-        if (shouldReturnLibVLCXML) {
-            replacementDict = @{@"FILES" : [mediaInXml componentsJoinedByString:@" "],
-                                @"NB_FILE" : [NSString stringWithFormat:@"%li", (unsigned long)mediaInXml.count],
-                                @"LIB_TITLE" : [currentDevice name]};
-
-            fileResponse = [[HTTPDynamicFileResponse alloc] initWithFilePath:[self filePathForURI:path]
-                                                               forConnection:self
-                                                                   separator:@"%%"
-                                                       replacementDictionary:replacementDict];
-            fileResponse.contentType = @"application/xml";
-        } else {
-            replacementDict = @{@"FILES" : [mediaInHtml componentsJoinedByString:@" "],
-                                @"WEBINTF_TITLE" : NSLocalizedString(@"WEBINTF_TITLE", nil),
-                                @"WEBINTF_DROPFILES" : NSLocalizedString(@"WEBINTF_DROPFILES", nil),
-                                @"WEBINTF_DROPFILES_LONG" : [NSString stringWithFormat:NSLocalizedString(@"WEBINTF_DROPFILES_LONG", nil), deviceModel],
-                                @"WEBINTF_DOWNLOADFILES" : NSLocalizedString(@"WEBINTF_DOWNLOADFILES", nil),
-                                @"WEBINTF_DOWNLOADFILES_LONG" : [NSString stringWithFormat: NSLocalizedString(@"WEBINTF_DOWNLOADFILES_LONG", nil), deviceModel]};
-            fileResponse = [[HTTPDynamicFileResponse alloc] initWithFilePath:[self filePathForURI:path]
-                                                               forConnection:self
-                                                                   separator:@"%%"
-                                                       replacementDictionary:replacementDict];
-            fileResponse.contentType = @"text/html";
-        }
+    UIDevice *currentDevice = [UIDevice currentDevice];
+    NSString *deviceModel = [currentDevice model];
+    NSDictionary *replacementDict;
+    HTTPDynamicFileResponse *fileResponse;
+
+    if (shouldReturnLibVLCXML) {
+        replacementDict = @{@"FILES" : [mediaInXml componentsJoinedByString:@" "],
+                            @"NB_FILE" : [NSString stringWithFormat:@"%li", (unsigned long)mediaInXml.count],
+                            @"LIB_TITLE" : [currentDevice name]};
+
+        fileResponse = [[HTTPDynamicFileResponse alloc] initWithFilePath:[self filePathForURI:path]
+                                                           forConnection:self
+                                                               separator:@"%%"
+                                                   replacementDictionary:replacementDict];
+        fileResponse.contentType = @"application/xml";
+    } else {
+        replacementDict = @{@"FILES" : [mediaInHtml componentsJoinedByString:@" "],
+                            @"WEBINTF_TITLE" : NSLocalizedString(@"WEBINTF_TITLE", nil),
+                            @"WEBINTF_DROPFILES" : NSLocalizedString(@"WEBINTF_DROPFILES", nil),
+                            @"WEBINTF_DROPFILES_LONG" : [NSString stringWithFormat:NSLocalizedString(@"WEBINTF_DROPFILES_LONG", nil), deviceModel],
+                            @"WEBINTF_DOWNLOADFILES" : NSLocalizedString(@"WEBINTF_DOWNLOADFILES", nil),
+                            @"WEBINTF_DOWNLOADFILES_LONG" : [NSString stringWithFormat: NSLocalizedString(@"WEBINTF_DOWNLOADFILES_LONG", nil), deviceModel]};
+        fileResponse = [[HTTPDynamicFileResponse alloc] initWithFilePath:[self filePathForURI:path]
+                                                           forConnection:self
+                                                               separator:@"%%"
+                                                   replacementDictionary:replacementDict];
+        fileResponse.contentType = @"text/html";
+    }
+
+    return fileResponse;
+}
 #else
-        UIDevice *currentDevice = [UIDevice currentDevice];
-        NSString *deviceModel = [currentDevice model];
-        NSString *filePath = [self filePathForURI:path];
-        NSString *documentRoot = [config documentRoot];
-        NSString *relativePath = [filePath substringFromIndex:[documentRoot length]];
-        NSDictionary *replacementDict = @{@"WEBINTF_TITLE" : NSLocalizedString(@"WEBINTF_TITLE_ATV", nil),
-                                          @"WEBINTF_DROPFILES" : NSLocalizedString(@"WEBINTF_DROPFILES", nil),
-                                          @"WEBINTF_DROPFILES_LONG" : [NSString stringWithFormat:NSLocalizedString(@"WEBINTF_DROPFILES_LONG_ATV", nil), deviceModel]};
-
-        HTTPDynamicFileResponse *fileResponse;
-        if ([relativePath isEqualToString:@"/index.html"]) {
-            fileResponse = [[HTTPDynamicFileResponse alloc] initWithFilePath:[self filePathForURI:path]
-                                                               forConnection:self
-                                                                   separator:@"%%"
-                                                       replacementDictionary:replacementDict];
-            fileResponse.contentType = @"text/html";
+- (NSObject<HTTPResponse> *)_httpGETLibraryForPath:(NSString *)path
+{
+    UIDevice *currentDevice = [UIDevice currentDevice];
+    NSString *deviceModel = [currentDevice model];
+    NSString *filePath = [self filePathForURI:path];
+    NSString *documentRoot = [config documentRoot];
+    NSString *relativePath = [filePath substringFromIndex:[documentRoot length]];
+    NSDictionary *replacementDict = @{@"WEBINTF_TITLE" : NSLocalizedString(@"WEBINTF_TITLE_ATV", nil),
+                                      @"WEBINTF_DROPFILES" : NSLocalizedString(@"WEBINTF_DROPFILES", nil),
+                                      @"WEBINTF_DROPFILES_LONG" : [NSString stringWithFormat:NSLocalizedString(@"WEBINTF_DROPFILES_LONG_ATV", nil), deviceModel]};
+
+    HTTPDynamicFileResponse *fileResponse;
+    if ([relativePath isEqualToString:@"/index.html"]) {
+        fileResponse = [[HTTPDynamicFileResponse alloc] initWithFilePath:[self filePathForURI:path]
+                                                           forConnection:self
+                                                               separator:@"%%"
+                                                   replacementDictionary:replacementDict];
+        fileResponse.contentType = @"text/html";
+    }
+
+    return fileResponse;
+}
 #endif
 
-        return fileResponse;
-    } else if ([relativePath isEqualToString:@"/style.css"]) {
+
+- (NSObject<HTTPResponse> *)_httpGETCSSForPath:(NSString *)path
+{
 #if TARGET_OS_IOS
-        NSDictionary *replacementDict = @{@"WEBINTF_TITLE" : NSLocalizedString(@"WEBINTF_TITLE", nil)};
+    NSDictionary *replacementDict = @{@"WEBINTF_TITLE" : NSLocalizedString(@"WEBINTF_TITLE", nil)};
 #else
-        NSDictionary *replacementDict = @{@"WEBINTF_TITLE" : NSLocalizedString(@"WEBINTF_TITLE_ATV", nil)};
+    NSDictionary *replacementDict = @{@"WEBINTF_TITLE" : NSLocalizedString(@"WEBINTF_TITLE_ATV", nil)};
 #endif
-        HTTPDynamicFileResponse *fileResponse = [[HTTPDynamicFileResponse alloc] initWithFilePath:[self filePathForURI:path]
-                                                                                    forConnection:self
-                                                                                        separator:@"%%"
-                                                                            replacementDictionary:replacementDict];
-        fileResponse.contentType = @"text/css";
-        return fileResponse;
+    HTTPDynamicFileResponse *fileResponse = [[HTTPDynamicFileResponse alloc] initWithFilePath:[self filePathForURI:path]
+                                                                                forConnection:self
+                                                                                    separator:@"%%"
+                                                                        replacementDictionary:replacementDict];
+    fileResponse.contentType = @"text/css";
+    return fileResponse;
+}
+
+
+- (NSObject<HTTPResponse> *)httpResponseForMethod:(NSString *)method URI:(NSString *)path
+{
+    if ([method isEqualToString:@"POST"] && [path isEqualToString:@"/upload.json"])
+        return [self _httpPOSTresponseUploadJSON];
+
+#if TARGET_OS_IOS
+    if ([path hasPrefix:@"/download/"]) {
+        return [self _httpGETDownloadForPath:path];
+    }
+    if ([path hasPrefix:@"/thumbnail"]) {
+        return [self _httpGETThumbnailForPath:path];
+    }
+#endif
+
+    NSString *filePath = [self filePathForURI:path];
+    NSString *documentRoot = [config documentRoot];
+    NSString *relativePath = [filePath substringFromIndex:[documentRoot length]];
+
+    if ([relativePath isEqualToString:@"/index.html"] || [relativePath isEqualToString:@"/libMediaVLC.xml"]) {
+        return [self _httpGETLibraryForPath:path];
+    } else if ([relativePath isEqualToString:@"/style.css"]) {
+        return [self _httpGETCSSForPath:path];
     }
 
     return [super httpResponseForMethod:method URI:path];

+ 14 - 5
VLC for iOS.xcodeproj/project.pbxproj

@@ -1189,8 +1189,6 @@
 				7D30F3CC183AB29300FFC021 /* VLCMenuTableViewController.m */,
 				7D30F3DD183AB31E00FFC021 /* VLCWiFiUploadTableViewCell.h */,
 				7D30F3DE183AB31E00FFC021 /* VLCWiFiUploadTableViewCell.m */,
-				7D30F3C5183AB26F00FFC021 /* VLCOpenNetworkStreamViewController.h */,
-				7D30F3C6183AB26F00FFC021 /* VLCOpenNetworkStreamViewController.m */,
 				7D30F3E0183AB33200FFC021 /* VLCSidebarViewCell.h */,
 				7D30F3E1183AB33200FFC021 /* VLCSidebarViewCell.m */,
 				7DAE0C351B2EF85B00C53996 /* VLCSidebarController.h */,
@@ -1372,10 +1370,9 @@
 				7D30F3BF183AB24C00FFC021 /* VLCHTTPFileDownloader.m */,
 				7D30F3C0183AB24C00FFC021 /* VLCHTTPUploaderController.h */,
 				7D30F3C1183AB24C00FFC021 /* VLCHTTPUploaderController.m */,
-				7D30F3C8183AB27A00FFC021 /* VLCDownloadViewController.h */,
-				7D30F3C9183AB27A00FFC021 /* VLCDownloadViewController.m */,
 			);
 			name = "HTTP Connectivity";
+			path = ../AspenProject;
 			sourceTree = "<group>";
 		};
 		7D6BEF1D19E027A100DF3972 /* Cloud */ = {
@@ -1510,11 +1507,11 @@
 				7D6B08BB174A72A900A05173 /* VLCConstants.h */,
 				7DBBF180183AB3B80009A339 /* VLCAppDelegate.h */,
 				7DBBF181183AB3B80009A339 /* VLCAppDelegate.m */,
+				7DF383B41BF20E4600D71A5C /* Network dialogs */,
 				DD2789DF1B67A79700CED769 /* WatchSupport */,
 				7DBB788E1B305D8300894467 /* Keychain & random singletons */,
 				A7D03A4817A4249F0022C16F /* MediaDiscovering */,
 				7D2339AB176DE70E008D223C /* Menu */,
-				7D5F7ABA175265CB006CCCFA /* HTTP Connectivity */,
 				7D31002117B676D500E6516D /* Local Network Connectivity */,
 				7D5F7AB9175265B2006CCCFA /* Playback */,
 				7D5F7AB81752658E006CCCFA /* Everything Playlist */,
@@ -1794,6 +1791,17 @@
 			name = "Common Code";
 			sourceTree = "<group>";
 		};
+		7DF383B41BF20E4600D71A5C /* Network dialogs */ = {
+			isa = PBXGroup;
+			children = (
+				7D30F3C5183AB26F00FFC021 /* VLCOpenNetworkStreamViewController.h */,
+				7D30F3C6183AB26F00FFC021 /* VLCOpenNetworkStreamViewController.m */,
+				7D30F3C8183AB27A00FFC021 /* VLCDownloadViewController.h */,
+				7D30F3C9183AB27A00FFC021 /* VLCDownloadViewController.m */,
+			);
+			name = "Network dialogs";
+			sourceTree = "<group>";
+		};
 		7DF90B451BE7A8030059C0E3 /* Mini-InAppSettingsKit */ = {
 			isa = PBXGroup;
 			children = (
@@ -2093,6 +2101,7 @@
 		DD7110ED1AF38AFD00854776 /* SharedSources */ = {
 			isa = PBXGroup;
 			children = (
+				7D5F7ABA175265CB006CCCFA /* HTTP Connectivity */,
 				7D4DFEA81BDF982400979881 /* Cloud Integration */,
 				7DEC8BE21BD6880C006E1093 /* UI Elements */,
 				7DEC8BE01BD686D3006E1093 /* Playback */,