You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by GitBox <gi...@apache.org> on 2021/07/26 04:14:53 UTC

[GitHub] [james-project] vttranlina commented on a change in pull request #551: [WIP] [JAMES-3544] UploadRepository contract & InMemory implementationtemp

vttranlina commented on a change in pull request #551:
URL: https://github.com/apache/james-project/pull/551#discussion_r676279468



##########
File path: server/data/data-jmap/src/main/java/org/apache/james/jmap/api/model/Upload.scala
##########
@@ -0,0 +1,67 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.jmap.api.model
+
+import com.google.common.hash.Hashing
+import eu.timepit.refined.api.Refined
+import eu.timepit.refined.auto._
+import eu.timepit.refined.numeric.NonNegative
+import eu.timepit.refined.refineV
+import org.apache.james.jmap.api.model.Upload.Size
+import org.apache.james.mailbox.model.ContentType
+import org.slf4j.{Logger, LoggerFactory}
+
+import java.io.{ByteArrayInputStream, InputStream}
+
+object Upload {
+  private val logger: Logger = LoggerFactory.getLogger(classOf[Upload])
+  type Size = Long Refined NonNegative
+  val Zero: Size = 0L
+
+  def sanitizeSize(value: Long): Size = {
+    val size: Either[String, Size] = refineV[NonNegative](value)
+    size.fold(e => {
+      logger.error(s"Encountered an invalid Upload size: $e")
+      Zero
+    },
+      refinedValue => refinedValue)
+  }
+
+  def from(metaData: UploadMetaData, content: Array[Byte]): Upload =
+    Upload(uploadId = metaData.getUploadId,
+      size = Upload.sanitizeSize(metaData.getSize),

Review comment:
       `metaData.getSize` is not set by the client, It is set by the server when store upload (`content.length`). This purpose `def` is to convert data in the database to client response.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org