public static void uploadRepo(Long id, @Required File repo, String module, String version) throws ZipException, IOException { models.Upload upload = Uploads.getUpload(id); File uploadsDir = Util.getUploadDir(upload.id); if (validationFailed()) { Uploads.uploadRepoForm(id); } String name = repo.getName().toLowerCase(); if (name.endsWith(".zip")) uploadZip(repo, null, uploadsDir); else { boolean found = false; for (String postfix : SupportedExtensions) { if (name.endsWith(postfix)) { uploadArchive(repo, postfix, uploadsDir, module, version, id); found = true; break; } } if (!found) error( HttpURLConnection.HTTP_BAD_REQUEST, "Invalid uploaded file (must be zip, car, jar or src)"); } Uploads.view(id); }
public static void deleteFileAsync(Long id, String path) throws IOException { models.Upload upload = Uploads.getUpload(id); File uploadsDir = Util.getUploadDir(upload.id); File file = new File(uploadsDir, path); deleteFileImpl(path, file, uploadsDir, upload); String message = Scope.Flash.current().get("message"); renderJSON("{\"message\":\"" + message + "\"}"); }
public static void delete(Long id) throws IOException { models.Upload upload = getUpload(id); File uploadsDir = Util.getUploadDir(id); upload.delete(); FileUtils.deleteDirectory(uploadsDir); MyCache.evictUploadsForOwner(upload.owner); flash("message", "Upload repository deleted"); index(); }
public static void newUpload() throws IOException { models.Upload upload = new models.Upload(); upload.owner = getUser(); upload.created = Util.currentTimeInUTC(); upload.create(); File uploadDir = Util.getUploadDir(upload.id); if (!uploadDir.mkdirs()) throw new RuntimeException("Failed to create upload dir " + uploadDir.getAbsolutePath()); MyCache.evictUploadsForOwner(upload.owner); view(upload.id); }
public static void index() { User user = getUser(); List<models.Upload> uploads = user.uploads; List<UploadInfo> uploadInfos = new ArrayList<UploadInfo>(uploads.size()); for (models.Upload upload : uploads) { File uploadsDir = Util.getUploadDir(upload.id); UploadInfo uploadInfo = getUploadInfo(upload, uploadsDir, user); uploadInfos.add(uploadInfo); } render(uploadInfos); }
public static void listFolder(Long id, String path) throws IOException { models.Upload upload = getUpload(id); File uploadsDir = Util.getUploadDir(upload.id); File file = new File(uploadsDir, path); Uploads.checkUploadPath(file, uploadsDir); if (!file.exists()) notFound(path); if (file.isDirectory()) { render("Uploads/listFolder.html", upload, file); } else { notFound(); } }
public static void addChecksum(Long id, String path) throws IOException { models.Upload upload = Uploads.getUpload(id); File uploadsDir = Util.getUploadDir(upload.id); File file = new File(uploadsDir, path); checkUploadPath(file, uploadsDir); if (!file.exists()) notFound(path); Logger.info("add checksum: %s exists: %s", path, file.exists()); String sha1 = ModuleChecker.sha1(file); File sha1File = new File(uploadsDir, path + ".sha1"); FileUtils.write(sha1File, sha1); Uploads.view(id); }
public static void deleteFile(Long id, String path, boolean returnToBrowse) throws IOException { models.Upload upload = Uploads.getUpload(id); File uploadsDir = Util.getUploadDir(upload.id); File file = new File(uploadsDir, path); deleteFileImpl(path, file, uploadsDir, upload); if (returnToBrowse) { File parent = file.getParentFile(); String parentPath = JavaExtensions.relativeTo(parent, upload); // if we do viewFile directly we get silly %2F escapes in the URL redirect(Util.viewPublicUploadUrl(upload, parentPath)); } else { Uploads.view(id); } }
public static void view(Long id) throws IOException { models.Upload upload = getUpload(id); User user = getUser(); File uploadsDir = Util.getUploadDir(id); List<File> uploadedFiles = new ArrayList<File>(); collectFiles(uploadsDir, uploadedFiles); List<Module> modules = new ArrayList<Module>(); List<Diagnostic> diagnostics = ModuleChecker.collectModulesAndDiagnostics( uploadedFiles, modules, uploadsDir, user, upload); UploadInfo uploadInfo = new UploadInfo(upload, modules, diagnostics); String base = uploadsDir.getPath(); render("Uploads/view.html", upload, uploadInfo, uploadedFiles, base); }
public static void publish(Long id) throws IOException { models.Upload upload = getUpload(id); File uploadsDir = Util.getUploadDir(id); User user = getUser(); UploadInfo uploadInfo = getUploadInfo(upload, uploadsDir, user); if (!uploadInfo.isPublishable()) { Validation.addError(null, "Upload is not valid, cannot publish. Fix errors first."); prepareForErrorRedirect(); view(id); } List<models.ModuleVersion> versions = new LinkedList<models.ModuleVersion>(); for (Module module : uploadInfo.modules) { models.Module mod = models.Module.find("name = ?", module.name).first(); if (mod == null) { mod = new models.Module(); mod.name = module.name; mod.owner = user; mod.create(); } models.ModuleVersion modVersion = new models.ModuleVersion(); modVersion.module = mod; modVersion.version = module.version; modVersion.isCarPresent = module.car.exists; modVersion.isJarPresent = module.jar.exists; modVersion.isJsPresent = module.js.exists; modVersion.isSourcePresent = module.source.exists; modVersion.isScriptsPresent = module.scripts.exists; modVersion.isAPIPresent = module.docs.hasUnzipped; modVersion.isDocPresent = module.docs.exists; modVersion.isResourcesPresent = module.docs.exists; modVersion.isRunnable = module.isRunnable; modVersion.jvmBinMajor = module.jvmBinMajor; modVersion.jvmBinMinor = module.jvmBinMinor; modVersion.jsBinMajor = module.jsBinMajor; modVersion.jsBinMinor = module.jsBinMinor; modVersion.isNativeJvm = module.isNativeJvm(); modVersion.isNativeJs = module.isNativeJs(); modVersion.published = Util.currentTimeInUTC(); modVersion.doc = module.doc; modVersion.license = module.license; if (module.authors != null) { for (String author : module.authors) { modVersion.authors.add(Author.findOrCreate(author)); } } modVersion.create(); for (Import imp : module.getAllDependencies()) modVersion.addDependency( imp.name, imp.version, imp.optional, imp.export, imp.mavenDependency != null, imp.herdDependency != null, imp.isNativeJvm(), imp.isNativeJs()); for (ModuleChecker.Member member : module.members) modVersion.addMember(member.packageName, member.name, member.type, member.shared); for (ModuleChecker.Script script : module.scriptDescriptions) modVersion.addScript( script.name, script.description, script.unix, script.plugin, script.module); versions.add(modVersion); } FileUtils.copyDirectory(uploadsDir, Util.getRepoDir(), NonEmptyDirectoryFilter); FileUtils.deleteDirectory(uploadsDir); upload.delete(); MyCache.evictUploadsForOwner(user); MyCache.evictModulesForOwner(user); if (versions.size() == 1) { flash("message", "Your module has been published"); models.ModuleVersion moduleVersion = versions.get(0); Repo.view(moduleVersion.module.name, moduleVersion.version); } else { flash("message", "Your modules have been published"); render(versions); } }
@Transient public long getFileCount() { return JavaExtensions.countFiles(Util.getUploadDir(id)); }
@Transient public long getSize() { return JavaExtensions.folderSize(Util.getUploadDir(id)); }